latexcmd
USAGE: latexcmd(filename, var1, var2, ...)
Creates a LaTeX file with commands named as the corresponding Matlab variables. Include the resulting LaTeX file into your LaTeX document (by an \include{filename}) to access the variable values. Works on scalars, polynomials, numeric arrays, cell arrays, and structures. Also works with most types: numbers (real and complex), NaN, Inf, strings, syms (from the Symbolic Toolbox), function handles, and inlines (although functions look flat without the Symbolic TB).
If you find any errors, please let me know (peder at axensten dot se)!
INSPIRATION: latexcmd has the functionality of the similar mfiles latex, matrix2latex, MAT2TEX, latex_trick, mat2textable, but works on more variable and number types, and has a more flexible number format, when required. It can also save as many variables as you want in one file, as opposed to one file per variable in some older related mfiles.
ARGUMENTS:
filename must be a string. If prefixed by '>' (i.e. '>filename'), the results will be appended to previous file contents. If empty, results will be printed on the display.
var may be any of the following:
+ Arrays must be max 2dimensional.
+ Cell arrays may not be nested (contain structures or arrays).
+ Structures generates a header with field names, followed by hline, followed by actual values.
+ Character strings:
 '\myname': The name of the next expression.
 '@myprefix': The prefix of the following names.
 '%myformat': Defines a new active number format (e.g. '%12.5E'). Specials: '%r': fractions format of numbers (using rat). '%R': fractions format of numbers (using rat) with integer part. '%ns': power of ten suffix (e.g., k, M, etc.) (n is number of digits). '%nS': 'scientific notation', exponent multiple of 3. '%u & %g & %5.2f%%' formats array columns individually.
 '%stat': Statistics of the following array (all of it, not columnwise): length, min, max, range, mean, median, std, cov, and all of it collectively (see latexcmd_example.m). If the next expression is nonnumeric, '%stat' will be ignored.
 '%poly': Outputs the following array as a polynomial of 'x'.
 '%poly:myvar': Outputs the following array as a polynomial of myvar.
 Other strings will be output as they are.
EXAMPLE (See 'help latexcmd_example' for more detailed examples.):
 In Matlab mfile 
result= [1 2 3 4 5 6];
resultmean= mean(result);
latexcmd(results, result, resultmean);
 In your LaTeX file 
\include{results}
[and somewhere later]
The mean of the measurements is \resultmean, with individual results:
\begin{tabular}{r@{, }r@{, }r@{, }r@{, }r@{, and }r}\result\end{tabular}

LATEX COMMANDS:
The following LaTeX commands are defined (you may redefine them for other formatting): \integer{int}, \float{int}{decimal}, \integerE{int}{exp}, \floatE{int}{decimal}{exp}, \fraction{nom}{denom}, \numberdelimiter, \imsymb, \textmu, \NaN, \statAll{}{}{}{}{}{}{}{}.
HISTORY:
Version 1.0, 20060320.
Version 1.1, 20060329:
 Added the '%stat' option to output various statistical info on an array.
 Added '%poly'/'%poly:name' options to output an array as a polynomial.
 Individual column formatting didn't actually work (sorry!), now it does.
 Fixed a crash when filename was an empty string.
 Removed stuff that mlint complained about.
Version 1.2, 20060427:
 Better (?) help text (no code changes).
Version 1.3, 20060507:
 Prefix (with \) certain characters in char variables: $&%#_{}~^.
Version 1.4, 20060523:
 Fixed a bug appearing when latexcmd was called from a command window.
Version 1.5, 20060606:
 Fixed bugs in latexcmd_example.m.
 Objects of type inline are now treated the same as function_handle objects.
Version 1.6, 20060607:
 Additional type of formatting for real scalars using power of ten suffix, (M is 1e6 etc.). See '%^n', above.
 Fixed a pretty rare bug with %prefixed strings.
Version 1.7, 20060614:
 Fixed bug with onedim. structures (thanks Ted Rosenbaum for reporting it).
Version 1.8, 20060720:
 Added support for FixedPoint Toolbox fi objects (class embedded.fi).
 '%r' and '%R': fractions format of numbers, using rat().
 '%ns': scientific notation (exponent multiple of 3) with suffix.
 '%nS': scientific notation (exponent multiple of 3).
COPYRIGHT (C) Peder Axensten (peder at axensten dot se), 2006.
Cite As
Peder Axensten (2024). latexcmd (https://www.mathworks.com/matlabcentral/fileexchange/10434latexcmd), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
 MATLAB > Data Import and Analysis >
 MATLAB > Data Import and Analysis > Data Import and Export > Standard File Formats > LaTeX >
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version  Published  Release Notes  

1.0.0.0   Added support for FixedPoint Toolbox fi objects (class embedded.fi).
