-
-
Notifications
You must be signed in to change notification settings - Fork 879
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
Add ability to pass flags to dvisvgm when using tikz engine? #2038
Comments
Or even better, the
First part of
Somehow allowing for the |
As an attempted workaround to avoid making any changes to the core knitr code, I tried creating a function for use in
|
Apologies for yet another comment! Here's a working, slightly hacky workaround/solution that uses a chunk hook to rerun tikz-example.Rmd:
|
Please feel free to submit a PR. It appears simple enough to implement---perhaps add something like Line 309 in 55a2df9
|
Whoa, that was a super easy fix. PR #2039 fixes this issue and now this chunk will automatically embed fonts without needing the knit hook workaround above:
|
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary. |
Currently , if the
tikz
engine is used andfig.ext = "svg"
,dvisvgm
is called to convert a DVI version of the TikZ chunk to SVG. The shell command fordvisvgm
is hard-coded in the engine function:knitr/R/engine.R
Line 309 in 55a2df9
This makes it impossible to add any additional flags to the command. One situation where this might be useful is when embedding fonts. According to the first FAQ at dvisvgm's list, most web browsers and vector editors struggle with embedded fonts from TikZ output. This causes issues with
tikz
chunks too. For instance, here's a simple reprex:tikz-example.Rmd:
That will knit to HTML and include an SVG file, but the resulting SVG will use placeholder fonts:
If you open the resulting SVG file in Illustrator or Inkscape, it will complain about missing fonts.
If you run
dvisvgm
on the cached DVI file from the terminal and include--no-fonts
, text will be converted to outlines instead of embedded as text, and the resulting SVG will look 99% correct (the conversion to outlines isn't perfect, but it's close enough):It might be helpful to allow users to add additional options to
dvisvgm
when using thetikz
engine, or perhaps just have a logical flag for embedding fonts or not. Within theeng_tikz()
function, converting the tikz chunk to PNG allows for additional options fromoptions$engine.opts$convert.opts
:knitr/R/engine.R
Lines 311 to 315 in 55a2df9
I wonder if a similar approach could be used for SVG output, so users could do something like
engine.opts = list(embed_fonts = FALSE)
or something similar.By filing an issue to this repo, I promise that
xfun::session_info('knitr')
. I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version:remotes::install_github('yihui/knitr')
.I understand that my issue may be closed if I don't fulfill my promises.
The text was updated successfully, but these errors were encountered: