2

Assuming that I have some equations in latex

A_{m,n} =
 \begin{pmatrix}
  a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\
  a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\
  \vdots  & \vdots  & \ddots & \vdots  \\
  a_{m,1} & a_{m,2} & \cdots & a_{m,n}
 \end{pmatrix}

Can I compile this into a dvi file or svg path without adding extra code or extra clutter ? I would just like to set the font size, that's all, I would like to feed this code to latex and get a single image not just a whole document that is automatically fitting the given math equation.

user2485710
  • 767
  • 5
  • 9
  • @cmhughes I don't think so – user2485710 May 03 '14 at 22:56
  • 1
    then please edit your question to clarify what it is that you want. Because in my interpretation of your question, the accepted answer to the linked question would work for your needs too. – Paul Gessler May 03 '14 at 23:09
  • @PaulGessler that answer suggests to add the usual \documentclass<...> and \begin<..> tags, that's exactly what I'm trying to avoid. I don't have documents, I have math equations written using the tex syntax . – user2485710 May 03 '14 at 23:15
  • If you truly cannot add anything to this snippet, I think command-line MathJax is your best option. Because if you wanted to use this code with LaTeX, you'd need (at minimum) \usepackage{amsmath} (for the pmatrix environment), which would then require a \documentclass{<...>} (for the \usepackage{<...>}). – Paul Gessler May 03 '14 at 23:33
  • @PaulGessler did you managed to get that working ? Because it's listed as experimental and it doesn't even work with some entities like matrices and symbols like the + sign. – user2485710 May 03 '14 at 23:35
  • Nope, I've not tested any of that. But that's the only option I can see if you're unwilling/unable to use a document class and/or packages. – Paul Gessler May 03 '14 at 23:44

2 Answers2

2

Assuming you have code of equation in equation.tex, then it can be compiled using command:

pdflatex  '\documentclass{standalone} \usepackage{amsmath} \begin{document} $\input{equation}$ \end{document}'

You can also create a custom shell/batch file that will compile a file given a parameter.

Tahtisilma
  • 2,396
  • I must confess that I don't see how this approach is supposed to be either simpler or more parsimonious than providing the four simple instructions \documentclass{standalone}, \usepackage{amsmath}, \begin{document}, and \end{document} inside the .tex file that contains the equation of interest. I guess you're not actually claiming it's simpler or more parsimonious... – Mico May 04 '14 at 15:27
  • @Mico You have the advantage when you have many files with equations. Adding simple 5 lines N times over can be tiring. – Tahtisilma May 04 '14 at 15:54
2

Here's a solution that steals from one of the answers to Passing parameters to a document

The command pdflatex wrapper myequation produces a pdf with just

enter image description here

with this wrapper.tex

\def\ReadCommandLineArg#1 {%
  \def\CommandLineArg{#1}%
  \input{\jobname}}
\unless\ifdefined\CommandLineArg
\endinput\expandafter\expandafter\expandafter\ReadCommandLineArg\fi

\documentclass{article}
\pagestyle{empty} % suppress page number
\usepackage{amsmath}
\begin{document}
\begin{equation*}
\input{\CommandLineArg}
\end{equation*}
\end{document}

and your myequation.tex

A_{m,n} =
 \begin{pmatrix}
  a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\
  a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\
  \vdots  & \vdots  & \ddots & \vdots  \\
  a_{m,1} & a_{m,2} & \cdots & a_{m,n}
 \end{pmatrix}

If there's more white space than you want in the pdf you can crop it with pdfcrop.

I don't know what you mean by "set the font size". You could probably tinker with this idea to make it do that.

Edit: to crop automatically, use the standalone package with $...$ instead of the equation* environment, as in the other answer.

\def\ReadCommandLineArg#1 {%
  \def\CommandLineArg{#1}%
  \input{\jobname}}
\unless\ifdefined\CommandLineArg
\endinput\expandafter\expandafter\expandafter\ReadCommandLineArg\fi

\documentclass{standalone}
\usepackage{amsmath}
\begin{document}
$\input{\CommandLineArg}$
\end{document}

And, answering a question you haven't asked, but that may come up, you can have multiple aligned equations if you use aligned and not align:

\begin{aligned}
e^{i\pi} & = \cos(\pi) + i\sin(\pi) \\
& = -1 
\end{aligned}
Ethan Bolker
  • 9,333
  • 3
  • 42
  • 69
  • I haven't picked this solution because the output of the other command is already cropped, but thanks anyway. – user2485710 May 04 '14 at 19:48
  • Of course automatic cropping is better. See the edit above, using the standalone package. Now you can use either solution. – Ethan Bolker May 04 '14 at 20:35