Your third version \ieC
produces larger spacing since you have .
in text mode, i.e., the period ends a sentence. Usually one would probably write i.e.\ $x<2$
, which corresponds to your first version \ieA
. But it's up to you what you choose. Maybe in display math you'll prefer the larger spacing.
As for your second question, your \etc
doesn't work because it lacks \expandafter
. You test the next character with \@ifnextchar
, but have a look at your code: When in math mode, you test the \else
, and else you test the \fi
! I know, this is the point where programming TeX can drive you crazy. What you have to do: use \expandafter
to get rid of \else
and \fi
so that the \@ifnextchar
can actually see the next character.
Just as a side note: you should put some space between a \ne 0,
and b \ne 0
. Moreover, your code really contains a lot of %
s that could be omitted. Here's my solution for \etc
:
\documentclass{article}
\usepackage{amsmath}
\usepackage{xspace}
\makeatletter
\newcommand*{\textetc}{%
\@ifnextchar{.}
{etc}
{etc.\@\xspace}%
}
\newcommand*{\mathetc}{%
\@ifnextchar{.}
{\text{etc}}
{\text{etc.}}%
}
\makeatother
\newcommand*{\etc}{%
\ifmmode
\expandafter\mathetc
\else
\expandafter\textetc
\fi
}
\begin{document}\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| works now at the end of sentences!
\noindent
You should eat more fruit, i.e.\ apples, bananas, \etc. Next sentence.
\noindent
You should eat more fruit, i.e., apples, bananas, \etc but also tomatoes.
\end{document}
The code below should work:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{gensymb}
\begin{document}
Degree symbol in plain text works: 90° is a right angle.
Degree in math now work: $\cos(90\degree) = 0$.
\end{document}
Best Answer
fontspec
doesn't have an interface for substituting some characters with characters from a different font, but thankfully egreg provided a package to do just that: