I am trying to adapt Martin Scharrer's solution from Macros for common abbreviations to be able to use them in math mode. Yes I realize I am about to incur some criticism that I should just use \text{}
, but I'd prefer the macros to do the thinking for me.
I have three different versions of the
\ie
macro below and not sure which one is the correct one to use. The third one (\ieC
, which is what I have been using) seems to yields slightly different spacing.I am not able to figure out how to adapt the
\etc
macro for math mode to properly handle the case where there is a subsequent period as in\etc.
. Furthermore, it appears as if the addition of\ifmmode
screws up the\etc
macro such that it no longer works properly even in text mode if there is a trailing period.
If there was a version of the \xspace
macro that worked in math mode that would be great.
References:
Code:
\documentclass{article}
\usepackage{amsmath}
\usepackage{xspace}
\newcommand*{\ieA}{%
\ifmmode%
\text{i.e.}\ %
\else%
i.e.\@\xspace%
\fi%
}%
\newcommand*{\ieB}{%
\ifmmode%
\text{i.e.~}%
\else%
i.e.\@\xspace%
\fi%
}%
\newcommand*{\ieC}{%
\ifmmode%
\text{i.e. }%
\else%
i.e.\@\xspace%
\fi%
}%
\makeatletter
\newcommand*{\etc}{%
\ifmmode%
\@ifnextchar{.}{\text{etc}}{\text{etc.}}%
\else%
\@ifnextchar{.}%
{etc}%
{etc.\@\xspace}%
\fi%
}%
\makeatother
\begin{document}\noindent
$\ieA x < 2$ \quad \verb|\text{i.e.}\ |\par\noindent
$\ieB x < 2$ \quad \verb|\text{i.e.~}|\par \noindent
$\ieC x < 2$ \quad \verb|\text{i.e. }|\par\noindent
\medskip\noindent
$a \ne 0, b \ne 0, \etc$\par\noindent
$a \ne 0, b \ne 0, \etc.$\par\noindent
\medskip\noindent
$a \ne 0, b \ne 0, \text{\etc}$ \quad \verb|\text{\etc}|\par\noindent
$a \ne 0, b \ne 0, \text{\etc.}$\quad \verb|\text{\etc.}|\par\noindent
\bigskip
\noindent
Outside of math mode \verb|\etc| no longer works at the end of sentence
\noindent
You should eat more fruit, \ieA apples, bananas, \etc. Next sentence.
\noindent
You should eat more fruit, \ieA, apples, bananas, \etc but also tomatoes.
\end{document}
The above MWE was for testing purposes, so I agree that the abbreviations there are not necessary to be within the math environment in those cases. But for my actual use case is in display mode where it is clearer to put that text as part of the formula as opposed to on the next line. For example:
\etc
work for you, or is there any way I could improve my answer?\ie
an\eg
(without the check for the.
since these are not intended to be used at the end of sentence). Initially this appeared to not be working, so had intended to come back to find out why. Turns out I had an extra brace group that was causing problem, so your solution now works for me in all the cases I can think of. Thanks.