showyourwork / showyourwork

A workflow for reproducible and open scientific articles

Home Page:https://show-your.work

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`\variable` command does not work inside `\caption{...}`

rmnldwg opened this issue · comments

First, thanks a lot for this great tool! I really like the idea of making everything except the text itself dynamic.

I am currently writing a paper using showyourwork and have stumbled across something that I couldn't resolve for quite a while: One of my rules kept being ignored and thus it broke my remote builds in particular. Eventually, I figured out that one \variable{output/...} command was inside the \caption{...} of a figure environment. Apparently, this causes the file inside the \variable command not to be part of the workflow graph. Below is a minimal example:

If I have something like this in my main ms.tex

\begin{figure}
    \centering
    \includegraphics[width=\linewidth]{figures/test.png}
    \caption{In this caption, I wanted to include \variable{output/inside.txt}, but it doesn't work.}
    \label{fig:one}
\end{figure}

Outside the figure environment, I can put \variable{output/outside.txt}.

and corresponding rules in the Snakefile

rule inside_figure_env:
    output: "src/tex/output/inside.txt"
    shell: "echo 'some text' > src/tex/output/inside.txt"

rule outside_figure_env:
    output: "src/tex/output/outside.txt"
    shell: "echo 'whatever I want' > src/tex/output/outside.txt"

Then the inside_figure_env rule will be ignored and the build will fail as long as src/tex/output/inside.txt is missing. In my case, I had a Python script that depended on some data. Changing the script or said data also did not trigger a recomputation of the rule as one would expect.

I hope this helps. Thanks a lot for the great work!

Can you try wrapping the \variable in a \protect?

\variable is a wrapper round \input and I have had some success with this solution before https://tex.stackexchange.com/questions/207905/using-input-inside-caption

Unfortunately, that did not work.

I think the issue isn't the \input command: If the file output/inside.txt in the above example is present, it compiles just fine. The issue is just that the workflow does not get triggered by a \variable inside a \caption.

What does work is to create an additional dependency in the showyourwork.yml:

dependencies:
  src/tex/ms.tex:
    - src/tex/output/inside.txt

Then, one can also simply use the \input command, since adding this dependency implicitly is the main purpose of \variable, if I understood that correctly.

Darn, sorry about that. I think that your work-a-round is good for now and I will try and have a look in the code in the coming weeks.