TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am writing a paper discussing numerical results of simulations. I am still tuning those simulations itself, so the results keep changing slightly. I don't want to re-type numbers over from what I computed all the time into the LaTeX document by hand.

I am currently using python to extract results and spit it out files in LaTeX format which are then \include'd (tabulars with numbers, basically), but this approach is not very flexible -- in particular, I can't refer to those numbers in running text.

Is there a packaged way to have e.g. text file with name value lines and then refer to value using \name in LaTeX, or something similar?

share|improve this question
If you're scripting your output into LaTeX tabular code, rather use \input. Perhaps the datatool package could be of help here. It allows you to read data from a CSV file and perform operations/tests on the database entries. – Werner Oct 27 '11 at 8:13
up vote 7 down vote accepted

Tell your Python script to write lines


instead of simply

name value

to your data files to be \input{}ed. Then \name in your main document will expand to the current value. However, with this approach the control sequence name may only contain letters. For general cs names, such as letters mixed with numbers and special characters, say name_1,

\expandafter\def\csname name_1\endcsname{value}%

must be written to the data file.

\csname name_1\endcsname then expands to its value wherever you place it in your main document.

Don't forget to terminate data lines with %. It avoids spurious spaces in the final LaTeX output.

share|improve this answer
Nice idea! That solves the problem very elegantly. – eudoxos Oct 27 '11 at 8:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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