Kāda ir "labākā LaTeX prakse" absolūtās vērtības simbolu rakstīšanai? Vai ir kādas paketes, kas piedāvā labas metodes?
Daži varianti ir |x|
un \mid x \mid
, bet es neesmu pārliecināts, kurš ir labākais...
Es izmantoju tālāk norādīto kodu, izmantojot \DeclarePairedDelimiter
no mathtools
paketes.
Tā kā es nedomāju, ka man ir gadījums, kad es nevēlos, lai tas tiktu mērogots atkarībā no parametra, es izmantoju https://tex.stackexchange.com/questions/23178/swap-definition-of-starred-and-non-starred-command, lai parastā lietošana tiktu automātiski mērogota, bet zvaigznītē atzīmētā versija netiktu mērogota:
Ja vēlaties, lai būtu otrādi, komentējiet kodu starp \makeatother...\makeatletter
.
\documentclass{article}
\usepackage{mathtools}
\DeclarePairedDelimiter\abs{\lvert}{\rvert}%
\DeclarePairedDelimiter\norm{\lVert}{\rVert}%
% Swap the definition of \abs* and \norm*, so that \abs
% and \norm resizes the size of the brackets, and the
% starred version does not.
\makeatletter
\let\oldabs\abs
\def\abs{\@ifstar{\oldabs}{\oldabs*}}
%
\let\oldnorm\norm
\def\norm{\@ifstar{\oldnorm}{\oldnorm*}}
\makeatother
\newcommand*{\Value}{\frac{1}{2}x^2}%
\begin{document}
\[\abs{\Value} \quad \norm{\Value} \qquad\text{non-starred} \]
\[\abs*{\Value} \quad \norm*{\Value} \qquad\text{starred}\qquad\]
\end{document}
Ņemiet vērā, ka, izmantojot |
, tiek iegūta mathord atstarpe, kas atšķiras no atstarpes, ko jūs iegūtu no pārējiem mathopen/mathclose norobežotājiem vai no \left/\right
, pat ja \left/\right
neizstiepj simbolu. Personīgi es dodu priekšroku mathinner kreisās/ labās puses atstarpēm (pat ja @egreg saka, ka es parasti kļūdos:-)
\documentclass{amsart}
\begin{document}
$ \log|x||y|b $
$ \log\left|x\right|\left|y\right|b $
$ \log\mathopen|x\mathclose|\mathopen|y\mathclose|b $
\end{document}
Var izmantot arī pakotni commath
.
\documentclass{article}
\usepackage{commath}
\begin{document}
\[ \norm{a \vec{u}} = \abs{a} \, \norm{\vec{v}} \]
\end{document}