Recently me and some friends really got into "making everything compilable". More specifically, we need to do a lot of matlab calculations, and then we need to put the results into a tex document.
I've had some time left recently and decided to write a matlab script to output values and their uncertainty bounds to a file, in correct the correct form so they can be a called in LaTeX, with the correct number of significant digits and whatnot everything so no brains are needed. Let me show you an example:
1) I have a matlab script do.m
that uses data form input files, processes it
and calculates what I want, say values that are stored in a
and
b
.
2) at the end of the script I call my savefortex
script that saves variables a
and b
to a file, say out.txt
, which will look like
this:
\def\a{123}
\def\b{456}
3) I put \input{out.txt}
in my LaTeX document.
4) I setup my makefile so that it knows do.m
should be called to have the latest out.txt
.
This is very handy when it comas down to a large number of variables that have to be inputted. Recently I stumbled into a problem though. I usually name my variables an their corresponding uncertainty bound as follows: a
, s_a
, b, s_b
, etc. Yet this is not compatible with Tex. Try this at home
\def\s_a{10}
\def\s_b{20}
\s_a and \s_b.
It simply won't work. The same goes for a1
, a2
, etc. Yet something like:
\def\s_a{10}
\s_a
does work! It seems as if tex doesn't allow for multiple macro's that have an underscore to have the same text before the underscore, even if the text after the underscore is different (again, this is the same with numbers in the macro names). So whilst s_a
and s_b
are okay to use separately, if they are both defined tex cannot use either of them!
What would be a good solution to this? Any suggestions for a different naming scheme? Or perhaps there's another way to get data from a file (this would be nice, since input takes a lot of time when there are a lot of macro's defined)?
I would also like to be able to use siunitx
, so while \SI{\a+-\b}{\metre}
works, \SI{\a+-\s_a}{\metre}
does not. I would love it if it did.
latex
command to output directlyLaTex
Content. It is in the symbolic toolbox._
, by useing\catcode`_=11
before the new commands. But this is in general a bad idea, better use another naming sheme