[Tex/LaTex] How to define variables with white space

macrosmath-mode

I'm writing a LaTex document in which I must refer to some variables in some points of the document.
In order to ensure that each variable is written in the same way, I defined a LaTex variable for each of them.

\documentclass[border=10pt]{standalone}
\usepackage{algorithm,algpseudocode}

\newcommand{\varu}{\emph{u}}
\newcommand{\varv}{\emph{v}}
\newcommand{\varz}{\emph{z}}
\newcommand{\varTr}{\emph{Training}}
\newcommand{\varRzT}{$R_{\varz_{\varTr}$ } }
\newcommand{\varReaz}{$R_{EAz}$ }
\newcommand{\varRecScore}{$s(\varv, \vart | \varu)$ }
\newcommand{\varCS}{Cand Set}
\newcommand{\varw}{\emph{w}(\varu,\varv)}
\newcommand{\varBC}{$\mathrm{BC}_{suff}$}

\begin{document}
My text is quite long. In the text there can 
be referred some variables like \varu
which I would like is written as emph and after
the variable there is a white space.

Some of these variables are also inserted into 
an algorithm structure defined with algorithm.

\end{document}

I use these variables in some points of the document: in the text, in math mode and into an algorithm structure.
My problem is that if I use these variables in the text, there is no white space after them. (i.e. after variable \varu there is no space).

How can I resolve it?
I can't define \varu with the white space \newcommand{\varu}{\emph{u }} because when if the variable is followed by "." the white space is not correct.

Best Answer

Your approach is wrong under many respects.

  1. You should use math italic, not \emph, except for multiletter variables; on the other hand “Training” is text, so it should be upright.

  2. Math formulas should be in math mode, even if it's just one variable.

\newcommand{\varu}{u}
\newcommand{\varv}{v}
\newcommand{\varz}{z}
\newcommand{\varTr}{\mathrm{Training}}
\newcommand{\varRzT}{R_{\varz_{\varTr}}}
\newcommand{\varReaz}{R_{EAz}}
\newcommand{\varRecScore}{s(\varv,\vart\mid\varu)}
\newcommand{\varCS}{\mathrm{Cand\ Set}}
\newcommand{\varw}{w(\varu,\varv)}
\newcommand{\varBC}{\mathrm{BC}_{\mathrm{suff}}}

Then your text might be, more simply,

My text is quite long. In the text there can 
be referred some variables like $\varu$
and after the variable there is a white space.
\begin{equation}
(\varu,\varv) = \varu * \varv - \varRzT
\end{equation}
Related Question