3

With this code

\documentclass[a4paper,12pt]{article}
\usepackage{mathtools, mathrsfs}

%% Code for '\widebar' macro is courtesy of
%% https://tex.stackexchange.com/a/60253
\makeatletter
\let\save@mathaccent\mathaccent
\newcommand*\if@single[3]{%
  \setbox0\hbox{${\mathaccent"0362{#1}}^H$}%
  \setbox2\hbox{${\mathaccent"0362{\kern0pt#1}}^H$}%
  \ifdim\ht0=\ht2 #3\else #2\fi
  }
%The bar will be moved to the right by a half of \macc@kerna, which is computed by amsmath:
\newcommand*\rel@kern[1]{\kern#1\dimexpr\macc@kerna}
%If there's a superscript following the bar, then no negative kern may follow the bar;
%an additional {} makes sure that the superscript is high enough in this case:
\newcommand*\widebar[1]{\@ifnextchar^{{\wide@bar{#1}{0}}}{\wide@bar{#1}{1}}}
%Use a separate algorithm for single symbols:
\newcommand*\wide@bar[2]{\if@single{#1}{\wide@bar@{#1}{#2}{1}}{\wide@bar@{#1}{#2}{2}}}
\newcommand*\wide@bar@[3]{%
  \begingroup
  \def\mathaccent##1##2{%
%Enable nesting of accents:
    \let\mathaccent\save@mathaccent
%If there's more than a single symbol, use the first character instead (see below):
    \if#32 \let\macc@nucleus\first@char \fi
%Determine the italic correction:
    \setbox\z@\hbox{$\macc@style{\macc@nucleus}_{}$}%
    \setbox\tw@\hbox{$\macc@style{\macc@nucleus}{}_{}$}%
    \dimen@\wd\tw@
    \advance\dimen@-\wd\z@
%Now \dimen@ is the italic correction of the symbol.
    \divide\dimen@ 3
    \@tempdima\wd\tw@
    \advance\@tempdima-\scriptspace
%Now \@tempdima is the width of the symbol.
    \divide\@tempdima 10
    \advance\dimen@-\@tempdima
%Now \dimen@ = (italic correction / 3) - (Breite / 10)
    \ifdim\dimen@>\z@ \dimen@0pt\fi
%The bar will be shortened in the case \dimen@<0 !
    \rel@kern{0.6}\kern-\dimen@
    \if#31
      \overline{\rel@kern{-0.6}\kern\dimen@\macc@nucleus\rel@kern{0.4}\kern\dimen@}%
      \advance\dimen@0.4\dimexpr\macc@kerna
%Place the combined final kern (-\dimen@) if it is >0 or if a superscript follows:
      \let\final@kern#2%
      \ifdim\dimen@<\z@ \let\final@kern1\fi
      \if\final@kern1 \kern-\dimen@\fi
    \else
      \overline{\rel@kern{-0.6}\kern\dimen@#1}%
    \fi
  }%
  \macc@depth\@ne
  \let\math@bgroup\@empty \let\math@egroup\macc@set@skewchar
  \mathsurround\z@ \frozen@everymath{\mathgroup\macc@group\relax}%
  \macc@set@skewchar\relax
  \let\mathaccentV\macc@nested@a
%The following initialises \macc@kerna and calls \mathaccent:
  \if#31
    \macc@nested@a\relax111{#1}%
  \else
%If the argument consists of more than one symbol, and if the first token is
%a letter, use that letter for the computations:
    \def\gobble@till@marker##1\endmarker{}%
    \futurelet\first@char\gobble@till@marker#1\endmarker
    \ifcat\noexpand\first@char A\else
      \def\first@char{}%
    \fi
    \macc@nested@a\relax111{\first@char}%
  \fi
  \endgroup
}
\makeatother
%% End of code block for \widebar macro


\begin{document}
\[
\begin{aligned}
\mathscr F(\bar{r}(t))&=& \int_a^{b} L dt& =&\int_a^{b} \left[L \frac{dt}{d\tau}\right]d\tau=\\
=\int_a^{b} \Bigl[-mc^2-q\varphi\dfrac{1}{\sqrt{1-\dfrac{u^{2}}{c^{2}}}}+q\frac{\bar{u}\cdot \widebar{A}}{\sqrt{1-\dfrac{u^{2}}{c^{2}}}}\Bigr]  d\tau=& &&&\\
=\int_a^{b} \left[-mc^2+q\,\boldsymbol{\mathcal{U}}\cdot \boldsymbol{\mathcal{A}}\right] d\tau&&&&\\
\end{aligned}
\]
\end{document}

I have this output:

enter image description here

However, I would like to have the following alignment as the image below:

enter image description here

In the last few days I have done several tests but I have not succeeded. For other formulas the alignment on the left is very good. With this formula I can't do it.

Lastly, how can I improve the shape of the integral of the second line where the two green rectangles are highlighted? The square brackets do not respect the length of the integral symbol.

Mico
  • 506,678
Sebastiano
  • 54,118
  • 2
    It is not eqnarray. Use a single & per line, before the first =. – egreg Mar 01 '19 at 23:34
  • @egreg Kindest Prof. I ask you a kindness; please can you give me a complete answer with the directions that I have given? I hope that the translation from Italian into English with DeepL is clear. Thank you in advance. – Sebastiano Mar 01 '19 at 23:36
  • 1
    Is it normal practice where you come from to have an = sign at the end of one line and the start of the next? because it definitely isn't here, you shouldn't have one at the end of the line – Au101 Mar 01 '19 at 23:37
  • @Au101 - Placing an = symbol both at the end of one line and at the start on the next line of a multiline equation is a common convention in some national typographic systems. – Mico Mar 02 '19 at 08:27
  • I've take the liberty of adding a note to your code to mention that the \widebar macro comes from this answer to the query Can I get a \widebar without using the mathabx package? – Mico Mar 02 '19 at 08:28
  • In my opinion, in your example, the equal sign at the end of the line is useless. Only those written in columns are required. – AndréC Mar 02 '19 at 08:37
  • @AndréC - Whether or not the = at the ends of lines 1 and 2 are "useless" is immaterial if they are there because the OP must conform to an Italian typographic convention. – Mico Mar 02 '19 at 08:56
  • @Mico This is a strange convention since the equal sign is no longer seen as a relationship of equivalence. – AndréC Mar 02 '19 at 09:21
  • @Mico I see! You learn something new every day :) – Au101 Mar 02 '19 at 09:24
  • 2
    No downvotes so far -- what's going on?! :-) – Mico Mar 02 '19 at 10:04
  • @Mico Never Say Never is an old Sean Connery movie of 007. :-) Anything can happen. :-) – Sebastiano Mar 02 '19 at 10:09
  • @Mico Why should there be down votes? – AndréC Mar 02 '19 at 10:33
  • 1
    @AndréC Because there are frequent times of the year that haters attack me. – Sebastiano Mar 02 '19 at 10:36
  • @Sebastiano Why are they doing this? – AndréC Mar 02 '19 at 10:55
  • 2
    @AndréC - They just downvote, no explanations given, ever. And they really seem to like downvoting Sebastiano's queries. Who knows what motivates them? Maybe they dislike Saint Sebastian and believe it's appropriate to downvote queries by persons whose first name happens to be Sebastian[o]? At this point, any guess is as good, or bad, as any other. – Mico Mar 02 '19 at 11:00

4 Answers4

8

My mathematician's eyes bleed when I see something like

\frac{<whatever}{\sqrt{1-\dfrac{u^2}{c^2}}

appearing more than once; I guess in your document it appears many times.

\documentclass[a4paper,12pt]{article}
\usepackage{mathtools, mathrsfs,bm}

\makeatletter
%<...long code omitted for brevity...>
\makeatother

\begin{document}
\[
\begin{aligned}
\mathscr F(\bar{r}(t))
&= \int_a^{b} L dt = \int_a^{b} \left[L \frac{dt}{d\tau}\right]\,d\tau=\\
&=\int_a^{b} [-mc^2-q\varphi\gamma(u)+q\bar{u}\cdot \widebar{A}\gamma(u)] \,d\tau=\\
&=\int_a^{b} [-mc^2+q\,\bm{\mathcal{U}}\cdot \bm{\mathcal{A}}] \,d\tau\\
\end{aligned}
\]
where
\[
\gamma(u)=\left(1-\frac{u^2}{c^2}\right)^{-1/2}
\]
\end{document}

There should be a single & per line.

I also fixed the usage of \left and \right and loaded bm that performs better than amsbsy and its \boldsymbol command, replaced by \bm (but \boldsymbol works as well).

enter image description here

egreg
  • 1,121,712
  • 2
    What makes your mathematician's eyes bleed when you see this \frac{<whatever}{\sqrt{1-\dfrac{u^2}{c^2}}? – AndréC Mar 02 '19 at 09:31
  • @egreg Thank you so much for your patience and courtesy. – Sebastiano Mar 02 '19 at 09:52
  • @AndréC I think his eyes bleed because of the use of dfrac: it should (always) be frac. Even in this case the OP can use u^2/c^2 since it means the same but more compact. – manooooh Mar 20 '19 at 00:27
3

Here are some suggestions:

enter image description here

\documentclass{article}

\usepackage{mathtools,mathrsfs,bm,bigints}

\begin{document}

\[
  \begin{aligned}
    \mathscr{F}(\bar{r}(t)) &= \int_a^b L \,\mathrm{d}t = \int_a^b \left[L \dfrac{\mathrm{d}t}{\mathrm{d}\tau} \right] \,\mathrm{d}\tau = \\
      &= \bigint_a^b \left[ -m c^2 - q \varphi \dfrac{1}{\sqrt{1 - \dfrac{u^2}{c^2}}} + 
        q \frac{\bar{u} \cdot \bar{A}}{\sqrt{1 - \dfrac{u^2}{c^2}}} \right] \,\mathrm{d}\tau = \\
      &= \int_a^b \bigl[ -m c^2 + q\,\bm{\mathcal{U}} \cdot \bm{\mathcal{A}} \bigr] \mathrm{d}\tau
  \end{aligned}
\]

\begin{align*}
  \mathscr{F}(\bar{r}(t)) &= \int_a^b L \,\mathrm{d}t = \int_a^b \left[L \dfrac{\mathrm{d}t}{\mathrm{d}\tau} \right] \,\mathrm{d}\tau = \\
    &= \int_a^b \bigl( -m c^2 - q \varphi / \sqrt{1 - u^2 / c^2} + 
      q (\bar{u} \cdot \bar{A}) / \sqrt{1 - u^2 / c^2} \,\bigr) \,\mathrm{d}\tau = \\
    &= \int_a^b \bigl( -m c^2 + q\,\bm{\mathcal{U}} \cdot \bm{\mathcal{A}} \bigr) \,\mathrm{d}\tau
\end{align*}

\end{document}

The first suggestion uses an extended integral from bigints, but it places far too big an emphasis visually. Hence the second suggestion, and to use a less-intrusive fraction of the form a / b.

Werner
  • 603,163
2

First you had unnecessary ampersands, and others were missing.

To have some equations left aligned, the simplest way is to use the fleqn environment from nccmath. Further, I improved the layout of the middle row, using the \mfrac command (medium-sized fractions) instead of \dfrac.

\documentclass[a4paper,12pt]{article}
\usepackage{mathtools, mathrsfs, nccmath}
\usepackage[showframe]{geometry}
\makeatletter
\let\save@mathaccent\mathaccent
\newcommand*\if@single[3]{%
  \setbox0\hbox{${\mathaccent"0362{#1}}^H$}%
  \setbox2\hbox{${\mathaccent"0362{\kern0pt#1}}^H$}%
  \ifdim\ht0=\ht2 #3\else #2\fi
  }
%The bar will be moved to the right by a half of \macc@kerna, which is computed by amsmath:
\newcommand*\rel@kern[1]{\kern#1\dimexpr\macc@kerna}
%If there's a superscript following the bar, then no negative kern may follow the bar;
%an additional {} makes sure that the superscript is high enough in this case:
\newcommand*\widebar[1]{\@ifnextchar^{{\wide@bar{#1}{0}}}{\wide@bar{#1}{1}}}
%Use a separate algorithm for single symbols:
\newcommand*\wide@bar[2]{\if@single{#1}{\wide@bar@{#1}{#2}{1}}{\wide@bar@{#1}{#2}{2}}}
\newcommand*\wide@bar@[3]{%
  \begingroup
  \def\mathaccent##1##2{%
%Enable nesting of accents:
    \let\mathaccent\save@mathaccent
%If there's more than a single symbol, use the first character instead (see below):
    \if#32 \let\macc@nucleus\first@char \fi
%Determine the italic correction:
    \setbox\z@\hbox{$\macc@style{\macc@nucleus}_{}$}%
    \setbox\tw@\hbox{$\macc@style{\macc@nucleus}{}_{}$}%
    \dimen@\wd\tw@
    \advance\dimen@-\wd\z@
%Now \dimen@ is the italic correction of the symbol.
    \divide\dimen@ 3
    \@tempdima\wd\tw@
    \advance\@tempdima-\scriptspace
%Now \@tempdima is the width of the symbol.
    \divide\@tempdima 10
    \advance\dimen@-\@tempdima
%Now \dimen@ = (italic correction / 3) - (Breite / 10)
    \ifdim\dimen@>\z@ \dimen@0pt\fi
%The bar will be shortened in the case \dimen@<0 !
    \rel@kern{0.6}\kern-\dimen@
    \if#31
      \overline{\rel@kern{-0.6}\kern\dimen@\macc@nucleus\rel@kern{0.4}\kern\dimen@}%
      \advance\dimen@0.4\dimexpr\macc@kerna
%Place the combined final kern (-\dimen@) if it is >0 or if a superscript follows:
      \let\final@kern#2%
      \ifdim\dimen@<\z@ \let\final@kern1\fi
      \if\final@kern1 \kern-\dimen@\fi
    \else
      \overline{\rel@kern{-0.6}\kern\dimen@#1}%
    \fi
  }%
  \macc@depth\@ne
  \let\math@bgroup\@empty \let\math@egroup\macc@set@skewchar
  \mathsurround\z@ \frozen@everymath{\mathgroup\macc@group\relax}%
  \macc@set@skewchar\relax
  \let\mathaccentV\macc@nested@a
%The following initialises \macc@kerna and calls \mathaccent:
  \if#31
    \macc@nested@a\relax111{#1}%
  \else
%If the argument consists of more than one symbol, and if the first token is
%a letter, use that letter for the computations:
    \def\gobble@till@marker##1\endmarker{}%
    \futurelet\first@char\gobble@till@marker#1\endmarker
    \ifcat\noexpand\first@char A\else
      \def\first@char{}%
    \fi
    \macc@nested@a\relax111{\first@char}%
  \fi
  \endgroup
}
\makeatother

\begin{document}

\begin{fleqn}
\begin{align*}
\mathscr F(\bar{r}(t))&= \int_a^{b} L dt =\int_a^{b} \left[L \frac{dt}{d\tau}\right]d\tau=\\
 & =\int_a^{b} \Bigl[-mc^2-q\varphi\mfrac{1}{\sqrt{1-\mfrac{u^{2}\mathstrut}{c^{2}}}}+q\mfrac{\bar{u}\cdot \widebar{A}}{\sqrt{1-\mfrac{u^{2}}{c^{2}}}}\Bigr] d\tau=& &&&\\
 & =\int_a^{b} \left[-mc^2+q\,\boldsymbol{\mathcal{U}}\cdot \boldsymbol{\mathcal{A}}\right] d\tau\\
\end{align*}
\end{fleqn}

\end{document} 

enter image description here

Bernard
  • 271,350
1

A little bit late to the game, but hopefully still useful.

enter image description here

In addition to placing & alignment points where they're needed, the main change from your sample code is the use of inline-fraction notation for the denominator terms in the middle row. By the way, there is no need for \\ at the end of the final row of an aligned environment.

\documentclass[a4paper,12pt]{article}
\usepackage{mathtools, mathrsfs, bm}

%% Code for '\widebar' macro is from https://tex.stackexchange.com/a/60253/5001
\makeatletter
\let\save@mathaccent\mathaccent
\newcommand*\if@single[3]{%
  \setbox0\hbox{${\mathaccent"0362{#1}}^H$}%
  \setbox2\hbox{${\mathaccent"0362{\kern0pt#1}}^H$}%
  \ifdim\ht0=\ht2 #3\else #2\fi
  }
%The bar will be moved to the right by a half of 
%\macc@kerna, which is computed by amsmath:
\newcommand*\rel@kern[1]{\kern#1\dimexpr\macc@kerna}
%If there's a superscript following the bar, then no 
%negative kern may follow the bar; an additional {} 
%makes sure that the superscript is high enough in 
%this case:
\newcommand*\widebar[1]{\@ifnextchar^{{\wide@bar{#1}{0}}}{\wide@bar{#1}{1}}}
%Use a separate algorithm for single symbols:
\newcommand*\wide@bar[2]{\if@single{#1}{\wide@bar@{#1}{#2}{1}}{\wide@bar@{#1}{#2}{2}}}
\newcommand*\wide@bar@[3]{%
  \begingroup
  \def\mathaccent##1##2{%
%Enable nesting of accents:
    \let\mathaccent\save@mathaccent
%If there's more than a single symbol, use the first 
%character instead (see below):
    \if#32 \let\macc@nucleus\first@char \fi
%Determine the italic correction:
    \setbox\z@\hbox{$\macc@style{\macc@nucleus}_{}$}%
    \setbox\tw@\hbox{$\macc@style{\macc@nucleus}{}_{}$}%
    \dimen@\wd\tw@
    \advance\dimen@-\wd\z@
%Now \dimen@ is the italic correction of the symbol.
    \divide\dimen@ 3
    \@tempdima\wd\tw@
    \advance\@tempdima-\scriptspace
%Now \@tempdima is the width of the symbol.
    \divide\@tempdima 10
    \advance\dimen@-\@tempdima
%Now \dimen@ = (italic correction / 3) - (Breite / 10)
    \ifdim\dimen@>\z@ \dimen@0pt\fi
%The bar will be shortened in the case \dimen@<0 !
    \rel@kern{0.6}\kern-\dimen@
    \if#31
      \overline{\rel@kern{-0.6}\kern\dimen@\macc@nucleus\rel@kern{0.4}\kern\dimen@}%
      \advance\dimen@0.4\dimexpr\macc@kerna
%Place the combined final kern (-\dimen@) if it is >0 or if a superscript follows:
      \let\final@kern#2%
      \ifdim\dimen@<\z@ \let\final@kern1\fi
      \if\final@kern1 \kern-\dimen@\fi
    \else
      \overline{\rel@kern{-0.6}\kern\dimen@#1}%
    \fi
  }%
  \macc@depth\@ne
  \let\math@bgroup\@empty \let\math@egroup\macc@set@skewchar
  \mathsurround\z@ \frozen@everymath{\mathgroup\macc@group\relax}%
  \macc@set@skewchar\relax
  \let\mathaccentV\macc@nested@a
%The following initialises \macc@kerna and calls \mathaccent:
  \if#31
    \macc@nested@a\relax111{#1}%
  \else
%If the argument consists of more than one symbol, 
%and if the first token is a letter, use that letter 
%for the computations:
    \def\gobble@till@marker##1\endmarker{}%
    \futurelet\first@char\gobble@till@marker#1\endmarker
    \ifcat\noexpand\first@char A\else
      \def\first@char{}%
    \fi
    \macc@nested@a\relax111{\first@char}%
  \fi
  \endgroup
}
\makeatother

\begin{document}
\[
\begin{aligned}
\mathscr{F} (\bar{r}(t))
&=\int_a^{b} \! L \,dt 
 = \int_a^{b} \Bigl[L \frac{dt}{d\tau}\Bigr] d\tau = \\
&=\int_a^{b} \biggl[-mc^2-q\varphi\frac{1}{\sqrt{1-u^2/c^2}}
+q\frac{\bar{u}\cdot \widebar{A}}{\sqrt{1-u^2/c^2}}\biggr]  d\tau = \\
&=\int_a^{b} [-mc^2+q\,\bm{\mathcal{U}}\cdot \bm{\mathcal{A}}\,]\, d\tau
\end{aligned}
\]
\end{document}
Mico
  • 506,678
  • Thank you very much. I need everything to learn and to recognize the differences and tricks of the trade :-). The questions were all voted (as always) positively. – Sebastiano Mar 02 '19 at 09:51
  • 1
    @Sebastiano: I've modified the code, using \mfrac for all fractions in the middle row (I think it looks nicer). – Bernard Mar 02 '19 at 10:21
  • @Bernard I hope that the electronic translation is good: you like everyone else is as if you were at home when you write to me. Obviously the polite and sensitive ones. – Sebastiano Mar 02 '19 at 10:24