I generate certain values and print them in single .tex-files (example.tex) in python, mostly in the form \SI{<value>}{\percent} or as single lines for tabular environments & \SI{<value>}{\percent} & \SI{<value>}{\percent} & \SI{<value>}{\percent}.

However, I can easily use \input{example.tex} to include this value in normal text,align or tabular environments without any trouble. But when using it within a mathmode ($$, \[\], \ensuremath) of a table caption, the log files yields "...an extra }" at the place of input.

Pdflatex compiles and the value shows up, bit since the warning is an error, Id like to ask either:

1) Is the use of `\input{}` for this purpose generally recommended?
2) How to get rid of the error/what did I do wrong?

Below an MWE, test_size.tex consists purely of \SI{30}{\percent}.



    Normal inline mode works: \input{./values/test_size.tex}\\[1ex]
    Normal math inline mode works: $\input{./values/test_size.tex}$
        \caption{Math inline caption doesnt work: $\input{./values/test_size.tex}$}
        \textrm{align enviroment works: } \input{./values/test_size.tex}

EDIT: This would have helped as well. Sorry for double posting.


\input is an endangered species, it needs protection, use \protect\input instead.

Though, why would you include data like this in the first place?

  • Cheers. Ive never spent much thought about why not or what else. I used \input to include different sections and so far for me it is the easiest way to automatically use values generated in my python projects. I assume there are better ways, and eager to read up on it. Could you provide me with some keywords?
    – Pratched
    Mar 20 '20 at 16:26
  • That sees overly complicated. But ok, you do you, I'd probably make a macro such that you could just use \ExtVal{test_size} instead of writing this all the time. Then it is also much easier if you later on decide to move the data to a different folder.
    – daleif
    Mar 20 '20 at 16:30
  • Ah alright. I thought there are some other, more common ways without using \input in the first place. But sure, macros shorten my effort as well.
    – Pratched
    Mar 20 '20 at 16:35
  • 1
    External data can be inputted in many ways it all depends on how you are able to prepare the data. It should be a CSV file. It could a a latex file defining some data structures that can then be outputtet using an interface like I descibed above (having everything in just one file saves a lot of IO).
    – daleif
    Mar 20 '20 at 16:37
  • Could be, not should be
    – daleif
    Mar 20 '20 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.