I would like to build a macro converting the contents of its parameter to bold, whether be it text, inline equations or displayed equations. (I use an arrow for vectors, so this is not a problem.) I have therefore defined the following macro:
\def\makebold#1{{\bfseries\mathversion{bold}#1}}
The problem is that, if #1ends with a displayed equation, a horizontal space is added in front of the next line, as in the following:
\par\noindent Text1:
\makebold{one has \[x=y.\]}
Text2.
"Text2" is shifted by one space to the right with respect to "Text1".
I can get rid of this space if I define \makebold in this way:
\def\makebold#1{{\bfseries\mathversion{bold}#1}\ignorespaces}
The problem now is that legitimate spaces are removed too, as in the following example, in front of "Text2":
Text1: \makebold{one has $x=y$.} Text2.
So, how can I know if the macro parameter ends with a displayed equation? I have tried to test for a \belowdisplayskip or a \belowdisplayshortskip with a \lastskip (as in Add \par only if last paragraph did not end with displayed math and Remove excess space at end), but this works only if I insert \par after #1, and in case 2 above, I don't want to leave the horizontal mode. I have also tried to set \postdisplaypenalty to some magic value and to test if this value is inserted, but it doesn't work either.
@campa I know that I can insert a % after \makebold{...} if it ends with a displayed equation, but I often forget to do it. Here is a file you can compile:
\documentclass{article}
\usepackage{amsmath}
\def\makeboldfirst#1{{\bfseries\mathversion{bold}#1}}
\def\makeboldsecond#1{{\bfseries\mathversion{bold}#1}\ignorespaces}
\begin{document}
\par\noindent Text1:
\makeboldfirst{one has \[x=y.\]}
Text2. % Unwanted space before "text2".
Text1: \makeboldfirst{one has $x=y$.} Text2. % OK.
\par\noindent Text1:
\makeboldsecond{one has \[x=y.\]}
Text2. % OK
Text1: \makeboldsecond{one has $x=y$.} Text2. % Space disappears before "Text2".
Environment display math test: \makeboldsecond{\begin{align*}x=y\end{align*}} Text
\end{document}
@nameworks only in comments, not in questions or answers. – campa Feb 08 '18 at 13:33