[Tex/LaTex] Formatting LaTeX-dump from Mathematica equations for A4-paper without manual adjusting

formattingwolfram-mathematica

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*)

Out

\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)

\begin{equation}
\begin{split}
{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} \\
\right.
\end{split}
\end{equation}

Perhaps related

  1. How to break a long equation?

Best Answer

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.)

Notes:

  • 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.

Code

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\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!
\begin{subequations}
\begin{align}
      A' & =-\frac{ag}{A \sqrt{2 g h}}       \\
      B' & = \frac{2}{A}                     \\
\Delta u & = F1 + F2 - 1.2                   \\
\begin{split}
\Delta x & = h - a'                          \\
         & = h - \frac{(F1 + F2)^2}{2 a^2 g}
\end{split}
\end{align}
\end{subequations}
% if you leave this line blank, you get another paragraph
so
%
\begin{equation}\begin{split}
\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). \\
\end{split}\end{equation}
\end{document}

Output

enter image description here