pandoc / lua-filters

A collection of lua filters for pandoc
MIT License
602 stars 165 forks source link

Diagram generator tikZ example could be simplified #213

Open PeterSommerlad opened 2 years ago

PeterSommerlad commented 2 years ago

The tikZ example uses absolute values to crop the left margin from a picture. However, this is error prone and I think it might depend on the local latex installation. I suggest to add the following to the "additionalpackages" in the example, which will crop the resulting image automatically to its largest dimension, without having to consider any margins added by latex.

\standaloneconfig{varwidth=\paperwidth}

changing the corresponding part of readme.md and sample.md as

```{.tikz caption="This is an image, created by **TikZ i.e. LaTeX**."
     additionalPackages="\usepackage{adjustbox}\standaloneconfig{varwidth=\paperwidth}"}

\usetikzlibrary{arrows}
\tikzstyle{int}=[draw, fill=blue!20, minimum size=2em]
\tikzstyle{init} = [pin edge={to-,thin,black}]

\begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
      \node [int, pin={[init]above:$v_0$}] (a) {$\frac{1}{s}$};
      \node (b) [left of=a,node distance=2cm, coordinate] {a};
      \node [int, pin={[init]above:$p_0$}] at (0,0) (c)
        [right of=a] {$\frac{1}{s}$};
      \node [coordinate] (end) [right of=c, node distance=2cm]{};
      \path[->] (b) edge node {$a$} (a);
      \path[->] (a) edge node {$v$} (c);
      \draw[->] (c) edge node {$p$} (end) ;
\end{tikzpicture}

```

This would have helped me a lot to get started.

Alternatively, this option can be provided directly by the lua filter in its internal template (note this can be changed to a different value as above.)

local tikz_template = [[
\documentclass[varwidth=\paperwidth]{standalone}
\usepackage{tikz}
%% begin: additional packages
%s
%% end: additional packages
\begin{document}
%s
\end{document}
]]