PreTeXtBook / pretext

PreTeXt: an authoring and publishing system for scholarly documents
https://pretextbook.org
Other
254 stars 202 forks source link

Recompile a LaTeX image if neccessary #2142

Closed siefkenj closed 1 month ago

siefkenj commented 1 month ago

If Rerun to get is present in a .log file left over form a LaTeX compile, then the file needs to be recompiled to reach its final state. This can happen, e.g., for tikz images where it has saved position information to the .aux file.

This commit adds a check of the log file to see if an image needs recompilation and recompiles if necessary.

Fixes #2140

This code can be tested by running ./pretext/pretext -c latex-image -f svg -v [file location] on the example:

<pretext>

    <docinfo>
        <macros>
        \newcommand{\doubler}[1]{2#1}
        </macros>
        <latex-image-preamble>
            \usepackage[dvipsnames]{xcolor}
            \usepackage{tikz}
            \usepackage{nicematrix}
        </latex-image-preamble>
    </docinfo>

    <article xml:id="minimal">
        <title>A Minimal Article</title>

        <section xml:id="section-textual">
            <title>Just Some Text</title>

            <image width="50%">
                <latex-image>
                    \begin{tikzpicture}
                    \node{
                        $\begin{bNiceArray}{ccc|cc}[
                        code-before={\cellcolor{LimeGreen!72}{1-1,2-2,3-3}\cellcolor{NavyBlue!72}{1-2,2-3,3-4}\cellcolor{CornflowerBlue!72}{1-3,2-4,3-5}}
                        ]
                        3 \amp 4 \amp 0 \amp 1 \amp 4 \\
                        -2 \amp 3 \amp 1 \amp -2 \amp 3 \\
                        0 \amp 2 \amp 1 \amp 0 \amp 2
                        \end{bNiceArray}$
                    };
                \end{tikzpicture}
                </latex-image>
            </image>
        </section>

    </article>

</pretext>

If compiled correctly, you should see colored boxes along the diagonal of the matrix.

rbeezer commented 1 month ago

Thanks! Well, I'm no fan of sniffing around in big files for magic strings. BUT, if it works for latexmk I guess we can run with it. ;-)

Would you consider a similar PR for the main document processing? I think we just always do two passes. I know tcolorbox can sometimes require multiple passes.

Updating website examples presently...