[Tex/LaTex] Writing out calculations in LaTeX

formattingline-spacingmath-modespacing

LaTeX's fantastic for writing out papers with mathematics and mathematical results in them, but I've never really learned how to use it to type up calculations, as one would write them on a piece of paper, or a blackboard.

TL;DR is there a "paragraph mode" for mathematics?

What I mean by this is, when I write out my calculations, I usually want them in a display style, that is, I want the larger integral and summation signs, and the larger fractions, I want the limits above and below the symbols, that sort of thing, as you would write maths on a blackboard or a piece of homework.

The problem is, if you're writing out calculations, I was always taught to write them like, essentially, individual paragraphs. I was to have them flush with the left margin and I was to leave a line (or at least, some space) between each line of my calculation.

Clearly, consecutive \[ ... \]s are ill-suited to this and not just because of the centring. Suppose we have line 1, then line 2, and the left hand side of the = sign is different on each line, but then we wish to have an aligned equation, like this:

\[
  36V^{2} = A^{2}x^{2} - 2Ax^{4}
\]
\[
  V = \frac{1}{6}(A^{2}x^{2} - 2Ax^{4})^{\frac{1}{2}}
\]
\begin{flalign*}
  \frac{dV}{dx} &= \frac{2A^{2}x - 8Ax^{3}}{12\sqrt{A^{2}x^{2} -
      2Ax^{4}}} \\[12pt]
  &= \frac{A^{2}x - 4Ax^{3}}{6\sqrt{A^{2}x^{2} - 2Ax^{4}}}
\end{flalign*}

enter image description here

How are we to ensure consistent spacing between each line?

Traditionally I have used a bit of a hack, with its own imperfections.

\documentclass[fleqn,12pt]{article}
\usepackage[parfill]{parskip}
\usepackage{amsmath}
\setlength{\mathindent}{0pt}

\begin{document}

$\begin{displaystyle}
  36V^{2} = A^{2}x^{2} - 2Ax^{4} \\[12pt]
  V = \frac{1}{6}(A^{2}x^{2} - 2Ax^{4})^{\frac{1}{2}}
\end{displaystyle}$
\begin{flalign*}
  \frac{dV}{dx} &= \frac{2A^{2}x - 8Ax^{3}}{12\sqrt{A^{2}x^{2} -
      2Ax^{4}}} \\[12pt]
  &= \frac{A^{2}x - 4Ax^{3}}{6\sqrt{A^{2}x^{2} - 2Ax^{4}}}
\end{flalign*}

\end{document}

enter image description here

But I'm not longer confident this is ideal.

What I really want is:

  • All lines flush with the left margin
  • Perfectly consistent gap between all lines, including between single, independent lines of mathematics, each line in an aligned environment, the last independent single line and the first line of an aligned environment, and text
  • Display style
  • Ability to switch freely between aligned and unaligned maths and text

For example:

\documentclass[fleqn,12pt]{article}
\pagestyle{plain}
\usepackage[margin=1.8cm]{geometry}
\geometry{a4paper}
\usepackage[parfill]{parskip}
\usepackage{amsmath}
\usepackage{amssymb}
\setlength{\mathindent}{0pt}

\begin{document}

Let the volume of the container be denoted~$V$ and let the area be
denoted~$A$.

$\begin{displaystyle}
  36V^{2} = A^{2}x^{2} - 2Ax^{4} \\[\parskip]
  V = \frac{1}{6}(A^{2}x^{2} - 2Ax^{4})^{\frac{1}{2}}
\end{displaystyle}$
\begin{flalign*}
  \frac{dV}{dx} &= \frac{2A^{2}x - 8Ax^{3}}{12\sqrt{A^{2}x^{2} -
      2Ax^{4}}} \\[\parskip]
  &= \frac{A^{2}x - 4Ax^{3}}{6\sqrt{A^{2}x^{2} - 2Ax^{4}}}
\end{flalign*}
\begin{flalign*}
  \frac{dV}{dx} = 0 &\implies A^{2}x = 4Ax^{3} \\[\parskip]
  &\implies x = 0 \text{ or } x^{2} = \frac{A}{4} \\[\parskip]
  &\implies x = 0,\ \pm\frac{\sqrt{A}}{2}
\end{flalign*}
We discard $x = 0$ and $x = -\sqrt{A}/2$ since the length of the base
of the container can be neither 0 nor negative.

$\therefore$ $V$ is a maximum at $x = \sqrt{A}/2$.

\end{document}

enter image description here

What I'm aiming for is (in so far as possible) precisely this, but with perfectly even spacing between all lines and, if possible, a less ghastly source code. I mean \\[\parskip] (or, until recently, \\[12pt]) at the end of almost every line was okay before I read LaTeX: A Document Preparation System but now I feel like I must be doing something wrong!

Best Answer

If you really need to this then instead of using the parskip package you might try using a document class that is designed for this type of layout. One example comes from the Dutch TeX user group in the ntgclass collection. Using their artikel3 class with the fleqn option, setting the \mathindent to zero and using just standard amsmath environments equation(*), align(*) and split gives many of the features you request.

Sample output

\documentclass[fleqn,12pt]{artikel3}

\usepackage{amsmath}
\usepackage{amssymb}
\setlength{\mathindent}{0pt}

\begin{document}

Let the volume of the container be denoted~$V$ and let the area be
denoted~$A$.

\begin{equation*}
  36V^{2} = A^{2}x^{2} - 2Ax^{4}
\end{equation*}
\begin{equation*}
  V = \frac{1}{6}(A^{2}x^{2} - 2Ax^{4})^{\frac{1}{2}}
\end{equation*}
\begin{equation*}
  \begin{split}
  \frac{dV}{dx} &= \frac{2A^{2}x - 8Ax^{3}}{12\sqrt{A^{2}x^{2} -
      2Ax^{4}}} \\
  &= \frac{A^{2}x - 4Ax^{3}}{6\sqrt{A^{2}x^{2} - 2Ax^{4}}}
  \end{split}
\end{equation*}
\begin{align*}
  \frac{dV}{dx} = 0 &\implies A^{2}x = 4Ax^{3} \\
  &\implies x = 0 \text{ or } x^{2} = \frac{A}{4} \\
  &\implies x = 0,\ \pm\frac{\sqrt{A}}{2}
\end{align*}
We discard $x = 0$ and $x = -\sqrt{A}/2$ since the length of the base
of the container can be neither 0 nor negative.

$\therefore$ $V$ is a maximum at $x = \sqrt{A}/2$.

\end{document}

Note that there is a big difference whether there is a blank line or not between two consecutive display math environments in the source.

Another example is the classes from the koma bundle, which have a parskip option.
The code would be the same as above, just with the first line changed to e.g.

\documentclass[fleqn,12pt,parskip=full*]{scrartcl}

There are quite a number of different choices for the parskip value. See the bundles documentation for full information.

On the other hand I would strongly discourage writing in this way. Sequences of equations without intervening text giving the structure of the arguments is not good for the reader (including yourself). I would be strongly inclined to write something more in this style:

Sample output

\documentclass[a4paper,12pt]{article}

\usepackage[margin=1.8cm]{geometry}

\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}

Let the volume of the container be~$V$ and let the area~$A$.  Write
$x$ for the length of the base of the container.  We assume all three
quantities are strictly positive.

The geometry of the problem gives
  \begin{equation*}
  36V^{2} = A^{2}x^{2} - 2Ax^{4}
\end{equation*}
which we may solve to get
\begin{equation}
  \label{eq:V}
  V = \frac{1}{6}(A^{2}x^{2} - 2Ax^{4})^{1/2}.
\end{equation}

At a maximum we have \( dV/dx = 0 \).  Computing the derivative of
\eqref{eq:V}, we find
\begin{equation*}
  \begin{split}
    \frac{dV}{dx}
    &= \frac{2A^{2}x - 8Ax^{3}}{12\sqrt{A^{2}x^{2} - 2Ax^{4}}} \\
    &= \frac{A^{2}x - 4Ax^{3}}{6\sqrt{A^{2}x^{2} - 2Ax^{4}}}\\
    &= \frac{1}{6\sqrt{A^{2}x^{2} - 2Ax^{4}}} Ax(A-4x^2).
  \end{split}
\end{equation*}
So at a maximum either \( A = 0 \) or \( x = 0 \) or \( x = \pm \sqrt
A /2 \).  The positivity assumptions rule out the three cases \( A = 0
\), \( x = 0 \) and \( x = - \sqrt A/2 \), so the only candidate for a
maximum is at \( x = \sqrt A/2 \).

Now we explain why this is in fact a maximum and not some other critical
point\dots

\end{document}
Related Question