I asked this question here in Mathematica.SE but they encouraged to ask also on this site.

enter image description here

How can make this writing process easier from Mathematica to LaTeX? Please, note that I have a lot of variables and I want to make them visible to the reader, I am not much interested how but not over the page so have to break the equations and perhaps other formatting, possible to get it directly from Mathematica?

Mathematica Code

AA = -a*g/(A*(2*g*h)^(1/2));
aa = (F1 + F2)^2/(2*a^2*g);
BB = 2/A;
Du = F1 + F2 - 1.2;
Dx = h - aa;
Px = AA*Dx - BB*Du // Simplify;

{AA, aa, BB, Du, Dx, Px} // TeXForm (*perhaps wrong way here? I want to show the above lines fast and accessible to the reader*)


\left\{-\frac{a g}{\sqrt{2} A \sqrt{g h}},\frac{(\text{F1}+\text{F2})^2}{2 a^2
   g},\frac{2}{A},\text{F1}+\text{F2}-1.2,h-\frac{(\text{F1}+\text{F2})^2}{2 a^2 g},-\frac{\frac{\sqrt{2} a g
   \left(h-\frac{(\text{F1}+\text{F2})^2}{2 a^2 g}\right)}{\sqrt{g h}}+4. (\text{F1}+\text{F2}-1.2)}{2 A}\right\}

My by-hand edited thing, time-consuming (too long, have to break it somehow)

{A',a',B',\Delta u, \Delta x, \partial x} := \left\{
-\frac{a g}{\sqrt{2} A \sqrt{g h}}, \\
\frac{(\text{F1}+\text{F2})^2}{2 a^2 g}, \\
\frac{2}{A}, \\
\text{F1}+\text{F2}-1.2, \\
h-\frac{(\text{F1}+\text{F2})^2}{2 a^2 g}, \\
-\frac{\frac{\sqrt{2} a g \left(h-\frac{(\text{F1}+\text{F2})^2}{2 a^2 g}\right)}{\sqrt{g h}}+4. (\text{F1}+\text{F2}-1.2)}{2 A} \\

Perhaps related

  1. How to break a long equation?

This is a (typographically) response to OP's own answer.
(Sorry, still no Mathematica-automation answer. This seems to be a job for either Mathematica itself or a Preprocessor.)


  • Don't use blank lines to pad your math environment from the text. This introduces a new paragraph.
  • Don't use a space before a -. To LaTeX, these are two separate words (matrix and -case) and breaks hyphenation.
  • I removed two unnecassary parenthesis from the last equation.
  • The align environment produces separate equation numbers, not only one for four/five lines.
  • The split environment is used for the last lines in the first block because these really belong to on equation. (If you don't like the position of the equation number, you could drop thesplit environment and just use \notag in one of the lines.)
  • I didn't touch F1 and F2.
    Your Mathematica output set them in the current text font (could be italics). Without the knowledge what they stand for, I would recommend using either F_1 or \mathrm{F}1.


\section{V. State-function of linearized system}
% compare output of F to results in section 1 and 3
We need only height so the equations gets much simplified,
now from the matrix-case to scalars so that
% we don't want to have a new paragraph starting here, so: no blank line!
      A' & =-\frac{ag}{A \sqrt{2 g h}}       \\
      B' & = \frac{2}{A}                     \\
\Delta u & = F1 + F2 - 1.2                   \\
\Delta x & = h - a'                          \\
         & = h - \frac{(F1 + F2)^2}{2 a^2 g}
% if you leave this line blank, you get another paragraph
\partial_t x & = A' \Delta x - B' \Delta u\\
             & = - \frac{ag}{A \sqrt{2 g h}} \left(h - \frac{(F1 + F2)^2}{2 a^2 g}\right) 
                 - \frac{2}{A} \left(F1 + F2 - 1.2 \right). \\


enter image description here

| improve this answer | |
  • ...discussion here. – hhh Oct 14 '12 at 22:53
  • 1
    @hhh Don't put align environments inside other math environments (in your instance equation). Only split can be used inside other math environment (but not multiline). I seriously recommend reading the amsmath manual; this is explained on the very first pages, along with a few examples. – Qrrbrbirlbel Oct 14 '12 at 22:54
  • @hhh Furthermore, the -ed family can be also used inside other math environments but inner ampersands don't get aligned to outher ones (the cases environment is a special form of aligned). – Qrrbrbirlbel Oct 14 '12 at 23:04

I do not know how to get well-formatted Mathematica-dump so I used basic eq-split -block like below. It is relatively slow to type them but, currently without better solution, I use this -- perhaps this could be automated somehow: deduce something from equations and make it look nice.

enter image description here

\section{V. State -function of linearized system}
% compare output of F to results in section 1 and 3

We need only height so the equations gets much simplified, now from the matrix -case to scalars so that 

A'&=-\frac{ag}{A\sqrt{2 g h}} \\
B'&=\frac{2}{A} \\
\Delta u&=F1+F2-1.2 \\
\Delta x&=h-a' \\
&=h-\frac{(F1+F2)^2}{2 a^2 g} \\


\partial_tx &= A'\Delta x-B'\Delta u\\
&= \left(-\frac{ag}{A\sqrt{2 g h}}\right)\left(h-\frac{(F1+F2)^2}{2 a^2 g}\right)-\left(\frac{2}{A}\right)\left(F1+F2-1.2\right).\\
| improve this answer | |

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.