Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird interaction with lots of previous equations when generating PDF - flextable "fails" #636

Open
cschwarz-stat-sfu-ca opened this issue May 30, 2024 · 2 comments

Comments

@cschwarz-stat-sfu-ca
Copy link

Very strange issue that appears to be flextable related.
I have a quarto document (included at end). Compiles fine into HTML.
When I try and compile into PDF, I get a LateX error:

==> quarto preview testing2.qmd --to pdf --no-watch-inputs --no-browse
....

Rendering PDF
running xelatex - 1
This is XeTeX, Version 3.141592653-2.6-0.999995 (TeX Live 2023) (preloaded format=xelatex)
restricted \write18 enabled.
entering extended mode

updating tlmgr

updating existing packages
ERROR:
compilation failed- error
Extra \else.
\SetMathAlphabet ...g #1\space \endcsname #1\else
@latex@error {Encoding sc...
l.304 ...{\global\setmainfont{Helvetica}{speed}}}}
& \multicolumn{1}{>{\ragg...

see testing2.log for more information.

THe log file has the following error message:
...
LaTeX Font Info: Overwriting math alphabet \mathrm' in version normal'
(Font) non@alpherr\relax \GenericError { }{LaTeX
Error: \mathrm allowed only in math mode}{See the LaTeX manual or LaTeX Compan
ion for explanation.}{You're in trouble here. Try typing to proceed
.
(Font) If that doesn't work, type X to quit.}\math@bgro
up __um_switch_to:n {literal}_um_mathgroup_set:n {6}\egroup \math@bgroup _
um_switch_to:n {literal}__um_mathgroup_set:n {6}-\egroup -> TU/Helvetica(1)/m/
n on input line 323.
! Extra \else.
\SetMathAlphabet ...g #1\space \endcsname #1\else
@latex@error {Encoding sc...
l.323 ...al\setmainfont{Helvetica}{name_model}}}}
& \multicolumn{1}{>{\ragg...

...

This comes from the final flextable call.

If I reduce the number of previous equations, it eventually compiles.
If I run the same chunk BEFORE the equations (e.g. change the third chunk include: to true in the MWE), then it compiles just fine as well.

Session Info
R version 4.4.0 (2024-04-24)
Platform: x86_64-apple-darwin20
Running under: macOS Sonoma 14.5

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Vancouver
tzcode source: internal

attached base packages:
[1] stats4 splines stats graphics grDevices utils datasets methods base

other attached packages:
[1] VGAM_1.1-11 lubridate_1.9.3 forcats_1.0.0 stringr_1.5.1 dplyr_1.1.4 purrr_1.0.2 readr_2.1.5
[8] tidyr_1.3.1 tibble_3.2.1 tidyverse_2.0.0 SPAS_2024.1.31 RMark_3.0.0 Petersen_2024.1.1 multimark_2.1.6
[15] knitr_1.46 insight_0.19.11 ggplot2_3.5.1 flextable_0.9.6 BTSPAS_2024.5.9 binom_1.1-1.1 AICcmodavg_2.3-3

loaded via a namespace (and not attached):
[1] rstudioapi_0.16.0 jsonlite_1.8.8 R2WinBUGS_2.1-22.1 magrittr_2.0.3 farver_2.1.2
[6] rmarkdown_2.27 fs_1.6.4 ragg_1.3.2 vctrs_0.6.5 memoise_2.0.1
[11] terra_1.7-78 askpass_1.2.0 htmltools_0.5.8.1 usethis_2.2.3 curl_5.2.1
[16] rjags_4-15 raster_3.6-26 parallelly_1.37.1 unmarked_1.4.1 htmlwidgets_1.6.4
[21] plyr_1.8.9 cachem_1.1.0 TMB_1.9.11 uuid_1.2-0 mime_0.12
[26] lifecycle_1.0.4 pkgconfig_2.0.3 Matrix_1.7-0 R6_2.5.1 fastmap_1.2.0
[31] future_1.33.2 shiny_1.8.1.1 digest_0.6.35 numDeriv_2016.8-1.1 colorspace_2.1-0
[36] R2jags_0.8-5 pkgload_1.3.4 textshaping_0.4.0 timechange_0.3.0 fansi_1.0.6
[41] polyclip_1.10-6 abind_1.4-5 compiler_4.4.0 remotes_2.5.0 fontquiver_0.2.1
[46] withr_3.0.0 carData_3.0-5 pkgbuild_1.4.4 ggforce_0.4.2 lava_1.8.0
[51] MASS_7.3-60.2 openssl_2.2.0 sessioninfo_1.2.2 gfonts_0.2.0 tools_4.4.0
[56] zip_2.3.1 httpuv_1.6.15 future.apply_1.11.2 glue_1.7.0 nlme_3.1-164
[61] promises_1.3.0 grid_4.4.0 reshape2_1.4.4 generics_0.1.3 operator.tools_1.6.3
[66] gtable_0.3.5 tzdb_0.4.0 formula.tools_1.7.1 hms_1.1.3 data.table_1.15.4
[71] sp_2.1-4 xml2_1.3.6 car_3.1-2 utf8_1.2.4 pillar_1.9.0
[76] later_1.3.2 tweenr_2.0.3 lattice_0.22-6 survival_3.6-4 tidyselect_1.2.1
[81] fontLiberation_0.1.0 miniUI_0.1.1.1 expint_0.1-8 fontBitstreamVera_0.1.1 gridExtra_2.3
[86] crul_1.4.2 xfun_0.44 expm_0.999-9 statmod_1.5.0 devtools_2.4.5
[91] stringi_1.8.4 boot_1.3-30 codetools_0.2-20 evaluate_0.23 httpcode_0.3.0
[96] officer_0.6.6 msm_1.7.1 bbmle_1.0.25.1 gdtools_0.3.7 cli_3.6.2
[101] xtable_1.8-4 systemfonts_1.1.0 munsell_0.5.1 Rcpp_1.0.12 globals_0.16.3
[106] coda_0.19-4.1 bdsmatrix_1.3-7 parallel_4.4.0 ellipsis_0.3.2 profvis_0.3.8
[111] urlchecker_1.0.1 Brobdingnag_1.2-9 listenv_0.9.1 matrixcalc_1.0-6 mvtnorm_1.2-5
[116] actuar_3.3-4 scales_1.3.0 prodlim_2023.08.28 crayon_1.5.2 rlang_1.1.3

Here is the example file (change suffix from qmd.txt to qmd(


testing2.qmd.txt

@cschwarz-stat-sfu-ca
Copy link
Author

I tried removing equations in turn, and it fails with a particular equation (as seen in the revised MWE). This equation tried to render a subscript symbol (theta).
testing3.qmd.txt

@cschwarz-stat-sfu-ca
Copy link
Author

And the "winner" is a simple equation of
$$\exp{x}$$

The error must be caused when the font for "exp" conflicts somehow with the font specification used by flextable if flextable calls occurs after this. Again, if I put a call to flextable before the equation by changing the include: false to include: true , everything works out fine

Very odd.

Carl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant