dialoa / imagify Goto Github PK
View Code? Open in Web Editor NEWPandoc/Quarto filter to convert selected LaTeX elements to images in other output formats
Home Page: https://dialoa.github.io/imagify/
License: MIT License
Pandoc/Quarto filter to convert selected LaTeX elements to images in other output formats
Home Page: https://dialoa.github.io/imagify/
License: MIT License
In Quarto users shouldn't specify LaTeX packages as (LaTeX commands in) header-includes
. They should put them under the imagify
key.
format: pdf:
imagify
to LaTeX when targeting LaTeX or PDF. In Pandoc, generate raw header-includes. In Quarto, use quarto.doc.include_text('in-header', text)
and quarto.doc.use_latex_package(pkg, opt)
. See Quarto Lua API.To embed SVG files in data URLs the filter use base64url encoding. In Quarto the lbase64 library is available, the filter should use it.
When I imagify
a simple tex
command in Quarto with format: html
, things work as expected. However, when I change the format to revealjs
, I get a 404 error that the file cannot be found (even though an absolute link is provided to the existing file). Note that I am creating this issue with a PR ready, but I'm not entirely sure if this will add the full generality of the filter to all reveal
presentations.
Great filter BTW!
Does this work when the target output is not LaTeX/PDF? If yes, use it in Quarto
Improve Quarto documentation:
First of all, many thanks for this extension!
I am trying to use a macro and a tikzstyle
in a TikZ picture but they both seem to fail:
\newcommand{\env}{\mathcal{E}}
\tikzstyle{arrow} = [->, > = Latex, very thick]
I am going to show the problem with tikzstyle
only as I suspect the problems to be similar.
Here is the code that works (provided imagify is installed of course):
test_work.qmd:
---
title: "Test"
lang: en-GB
pdf-engine: lualatex
filters:
- imagify
imagify:
header-includes: |
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows.meta}
pdf-engine: lualatex
format:
html:
toc: true
pdf:
include-in-header:
- text: |
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows.meta}
---
![A test](./testFig_work.tex){#fig-testFig}
testFig_work.tex:
\begin{tikzpicture}
%% Define nodes
\node (N0) at (0, 0) {N0};
\node[right = of N0] (N1) {N1};
\draw[->, > = Latex, very thick] (N0) -- (N1);
\end{tikzpicture}
Here is the code that does not work:
test_fail.qmd:
---
title: "Test"
lang: en-GB
pdf-engine: lualatex
filters:
- imagify
imagify:
header-includes: |
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows.meta}
\tikzstyle{arrow} = [->, > = Latex, very thick]
pdf-engine: lualatex
format:
html:
toc: true
pdf:
include-in-header:
- text: |
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows.meta}
\tikzstyle{arrow} = [->, > = Latex, very thick]
---
![A test](./testFig_fail.tex){#fig-testFig}
testFig_fail.tex:
\begin{tikzpicture}
%% Define nodes
\node (N0) at (0, 0) {N0};
\node[right = of N0] (N1) {N1};
\draw[arrow] (N0) -- (N1);
\end{tikzpicture}
I gathered in a zip the four files.
I am doing anything wrong or is there a bug in transmitting the macros and tikzstyle
?
test.zip
Provide inkscape (cli) as an alternative PDF -> SVG converter.
The lazy:true
option sometimes crashes because the scr
variable is nil.
Deactivate embedding when extract-media is on.
This is due to a bug in Pandoc: instead of leaving data URLs as they are, it treats them as links to non-existent media files that it tries to extract, and converts the data URLs into link URL to non-existent files.
Check and document differences in LaTeX metadata between Pandoc and Quarto.
Make sure the filter handles both.
Use Quarto.log for error messages when the filter is run in quarto.
The filter uses dvisvgm. Provide the tex2pdf converter too.
From this discussion:
The filter looks for them both at the root and under imagify (the latter overriding the former). Seems fine?
Yes - It seems fine to me to use same name key as default Pandoc. What I am suggesting is doing some special treatment in Lua and not just passing them through to override. This way I think you could catch a raw content in LaTeX that would be removed in HTML output and use it for your HTML processing.
In Quarto, perhaps in Pandoc, consider whether some Imagifying/LaTeX metadata picked up by the filter should be removed in non-LaTeX/PDF output. E.g. LaTeX options at the root and the like.
Use quarto.doc.is_format() in Quarto
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.