• Typesetting long andcomplicated equations

    From Athel Cornish-Bowden@21:1/5 to All on Mon Dec 25 12:38:18 2023
    I tried to ask the following question at Stack Exchange, but for some
    reason (not explained) the system didn't allow me to log in, so I'm
    asking it here:

    I am converting a long document in Word to LaTeX. As I’m not the
    primary author I have only limited freedom to revise the text and
    equations — correcting obvious errors, OK, but otherwise following what
    the Word file has and not changing the symbols to I would have used. It contains some very long and complicated equations, such as the
    following:

    \documentclass[12pt,a4paper]{article}
    \usepackage{amsmath}
    \begin{document}

    \begin{align}
    \nonumber \mu_j^{*0} \approx \frac{T}{298.15} \cdot \mu^0_j +
    \left( 1 - \frac{T}{298.15} \right) \cdot h_j^0 + \hspace*{2cm}\\
    \nonumber \mathrm{switch_{H^+}} \cdot \nu_{\mathrm{H}\varepsilon j}
    \cdot R \cdot T \cdot
    \ln(10) \cdot \mathrm{pH}_c\hspace*{2cm}\\
    \nonumber - \mathrm{switch _{Mg}}\cdot \nu_{\mathrm{Mg} \varepsilon j}
    \left[
    \frac{T}{298.15} \cdot \mu^0_\mathrm{Mg^{2+}} - R \cdot T \cdot
    \ln{10} \cdot \mathrm{pMg}_c \right.\\
    \nonumber - \left. \left( 1 - \frac{T}{298.15}
    \right) \cdot h^0_\mathrm{Mg^{2+}}
    \right]
    \mathrm{switch}_I \cdot g_\mathrm{DH}(I,T) \cdot \hspace*{2cm}\\
    \nonumber \left[
    z_i^2 - \mathrm{switch_\mathrm{H^+}} \cdot \nu_{\mathrm{H} \varepsilon j} - \mathrm{Mg} \cdot 4\cdot \nu_{\mathrm{Mg}\varepsilon j}
    \right]x\hspace*{2cm}\\
    \mathrm{switch_{mM}}\cdot R \cdot T \cdot \ln\left( \frac{c^\mathrm{standard}}{c^\mathrm{physchemstandard}}
    \right)\hspace*{1cm}
    \end{align}

    \end{document}

    This produces more or less what I want: specifically, only the last
    line has an equation number, and the lines are approximately centred.
    However, it seems a very clunky solution and raises two questions:

    1. \nonumber before every line except the last is OK, but is there a
    way to get the same result with a general command without repeating
    \nonumber five times.

    2. Using \hspace* to centre the lines requires a lot of fiddling about
    to put the right arguments. Is there a better way? (I’ve tried obvious
    things like putting each line in \begin {center} …. \end{center}.)


    --
    Athel cb
    LaTeX user, but far from expert

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dr Engelbert Buxbaum@21:1/5 to All on Tue Dec 26 09:40:41 2023
    In article <kut7tcFalqcU1@mid.individual.net>, me@yahoo.com says...

    I tried to ask the following question at Stack Exchange, but for some
    reason (not explained) the system didn't allow me to log in, so I'm
    asking it here:

    I am converting a long document in Word to LaTeX. As I?m not the
    primary author I have only limited freedom to revise the text and
    equations ? correcting obvious errors, OK, but otherwise following what
    the Word file has and not changing the symbols to I would have used. It contains some very long and complicated equations

    1. \nonumber before every line except the last is OK, but is there a
    way to get the same result with a general command without repeating
    \nonumber five times.

    2. Using \hspace* to centre the lines requires a lot of fiddling about

    The align-environment can do much of the work for you, if you use the &
    to align the beginning of each line. The equations won't be centered,
    but the operation signs at the beginning of each line will align just
    right of the \approx, making it clear that all lines belong to the same equation:

    \begin{align}
    \nonumber \mu_j^{*0} \approx & \frac{T}{298.15} \cdot \mu^0_j + \left
    ( 1 - \frac{T}{298.15} \right) \cdot h_j^0 \\
    \nonumber & + \mathrm{switch_{H^+}} \cdot \nu_ {\mathrm{H}\varepsilon j} \cdot R \cdot T \cdot \ln(10) \cdot \mathrm
    {pH}_c \\
    \nonumber & - \mathrm{switch _{Mg}}\cdot \nu_
    {\mathrm{Mg} \varepsilon j} \left[ \frac{T}{298.15} \cdot \mu^0_\mathrm {Mg^{2+}} - R \cdot T \cdot
    \ln{10} \cdot \mathrm{pMg}_c \right.\\
    \nonumber & - \left. \left( 1 - \frac{T}{298.15}
    \right) \cdot h^0_\mathrm{Mg^{2+}}
    \right] \mathrm{switch}_I \cdot g_\mathrm{DH}(I,T) \\
    \nonumber & \cdot \left[z_i^2 - \mathrm{switch_ \mathrm{H^+}} \cdot \nu_{\mathrm{H} \varepsilon j} - \mathrm{Mg} \cdot 4
    \cdot \nu_{\mathrm{Mg}\varepsilon j} \right]x \\
    & \cdot \mathrm{switch_{mM}}\cdot R
    \cdot T \cdot \ln\left( \frac{c^\mathrm{standard}}{c^\mathrm {physchemstandard}} \right)
    \end{align}

    (at the beginning of the last line I added a \cdot so it, too, starts
    with an operation). Optionally, you may replace all \cdot by the more
    common \times.

    Hope that helps
    Engelbert

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Peter Flynn@21:1/5 to Dr Engelbert Buxbaum on Tue Dec 26 19:39:00 2023
    On 26/12/2023 08:40, Dr Engelbert Buxbaum wrote:
    In article <kut7tcFalqcU1@mid.individual.net>, me@yahoo.com says...
    [snip]

    IANAM :-) but...

    Optionally, you may replace all \cdot by the more common \times.

    I would definitely do that, because it makes the LH side of each line
    align better. The only manual adjustment I would make is to move the
    large open parenthesis at the start of line 4 slightly leftwards to
    improve the optical alignment.

    \nonumber&-\kern-2pt\left.\left(1-\frac{T}{298.15}\right)...

    Peter

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)