You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functionImage(el)
ifisLatexOutput() then--- check el.src for an svg extension--- re-assign el.src to the pdf or png version--- return the modified elementreturnelendendlocalfunctionisLatexOutput()
returnFORMAT=="latex" orFORMAT=="beamer" orFORMAT=="pdf"end
This should indeed be a built in feature (so leaving this open for resolution later on)
I got the filter working, but is it possible to have the absolute path to the image file within the filter? I was unable to find how.
For example, if the processed document is chapter/section/hello.qmd with intro.svg in it, I only get intro.svg and no way to get the chapter/section/intro.svg full path to access the image.
This would let me to automatic "lazy" pdf conversion within the filter.
The pandoc.path module (and maybe pandoc.system) can be helpful here. Maybe something like
local path = require 'pandoc.path'
local input_dir = path.directory(PANDOC_STATE.input_files[1])
local relative = path.join{input_dir, 'INPUT-RELATIVE-FILE-PATH-GOES-HERE'}
If you configure your filter to run after the quarto filters like this:
filters:
- quarto
- filter.lua
Then you'll get the right path (it will be chapter/section/intro.svg and the current working directory will be the project root, so that relative file reference will work).
I have been debating in my head whether user filters should run before or after Quarto filters --- this makes me think that I may have the default wrong (currently user filters run first).
I've changed the default to have user filters run after quarto filters here: 606f92f
So your filter should work w/o any special configuration.
We are ultimately going to need to allow fairly fine grained control (i.e. per filter) over where user filters run. We will will also need to make some of Quarto's higher level constructs like tabsets, callouts, etc. directly available to filters.
I think a nice way to solve this particular problem is to write the image filename without extension in the markdown source, e.g. write simply , and call quarto with the option --default-image-extension=svg to generate the web version, and with --default-image-extension=pdf to generate the PDF.
I'm very late to this party, but just wanted to share that I am using latexmk for the pdf and self-contained: true for html in a book project, and I'm able to see my .svg files just fine (no filter necessary for SVG files, but I do use a filter to convert PlantUML/Graphviz diagrams into SVG).
format:
html:
# needed for inline graphviz figuresself-contained: truepdf:
# has to be latexmk for graphviz/svg figurespdf-engine: latexmk
Activity
jjallaire commentedon Nov 21, 2021
The easiest thing to do would be to write a Lua filter (https://quarto.org/docs/authoring/shortcodes-and-filters.html#filters) that automatically uses a (pre-generated) PDF or PNG in place of SVG when rendering to PDF. It would look something like this:
This should indeed be a built in feature (so leaving this open for resolution later on)
kuon commentedon Nov 21, 2021
I got the filter working, but is it possible to have the absolute path to the image file within the filter? I was unable to find how.
For example, if the processed document is
chapter/section/hello.qmdwithintro.svgin it, I only getintro.svgand no way to get thechapter/section/intro.svgfull path to access the image.This would let me to automatic "lazy" pdf conversion within the filter.
tarleb commentedon Nov 22, 2021
The
pandoc.pathmodule (and maybepandoc.system) can be helpful here. Maybe something likejjallaire commentedon Nov 22, 2021
If you configure your filter to run after the quarto filters like this:
Then you'll get the right path (it will be
chapter/section/intro.svgand the current working directory will be the project root, so that relative file reference will work).I have been debating in my head whether user filters should run before or after Quarto filters --- this makes me think that I may have the default wrong (currently user filters run first).
jjallaire commentedon Nov 22, 2021
I've changed the default to have user filters run after quarto filters here: 606f92f
So your filter should work w/o any special configuration.
We are ultimately going to need to allow fairly fine grained control (i.e. per filter) over where user filters run. We will will also need to make some of Quarto's higher level constructs like tabsets, callouts, etc. directly available to filters.
sijow commentedon Dec 3, 2021
I think a nice way to solve this particular problem is to write the image filename without extension in the markdown source, e.g. write simply
, and callquartowith the option--default-image-extension=svgto generate the web version, and with--default-image-extension=pdfto generate the PDF.jjallaire commentedon Jan 8, 2022
FYI we now provide
default-image-extensionautomatically (it defaults topngand then usespdffor pdf formats): https://quarto.org/docs/authoring/figures-and-layout.html#multiformat-figuresbenabel commentedon Mar 14, 2022
@kuon I use this filter that uses inkscape to convert
svgtopdffor latex output.fuhrmanator commentedon Jun 18, 2022
I'm very late to this party, but just wanted to share that I am using
latexmkfor the pdf andself-contained: truefor html in a book project, and I'm able to see my .svg files just fine (no filter necessary for SVG files, but I do use a filter to convert PlantUML/Graphviz diagrams into SVG).The full repo is at https://github.com/fuhrmanator/quarto-test