Following this previous question, I have in my acronyms the same pattern I define in a \newcommand\BS
.
However, when I use \ensuremath
and type my acronym with no math environment, I get an obvious extra space before and after, whereas it's alright if I put it in math mode.
It has to do with When not to use \ensuremath for math macro but even if I follow the advice to put extra { }
inside \ensuremath{}
to surround my expression, I still get extra spacing.
NB :If you tell me "well put your acronym in math mode then", i'd reply "well I have to do that along my 1500 pages, so how can I avoid that ? 🙂 " and get the proper spacing in text ?
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{acro}
%\usepackage{xspace}
% with extra {} inside \ensuremath{ }
\newcommand{\BS}[2]{ \ensuremath{ { \mathcal{#1}_{\mathcal{#2} } } } }
\DeclareAcronym{ki}{
short= \BS{K}{I},
long = Knock-In
}
\begin{document}
When I use \acs{ki} in text there is obviously extra space before and after my acronym.
When I use $\acs{ki}$ in math there is the right space before and after my acronym.
\printacronyms
\end{document}
Best Answer
You're responsible of those spaces. I denote by
!
the significant ones and withx
those that are ignored because they are processed in math mode:Don't use
\ensuremath
in the definition of\BS
: you gain nothing in being able to typesome \BS{K}{I} text
instead of the clearer and more semanticsome $\BS{K}{I}$ text
. There are also useless braces that are better removed.