3

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.

  • 6
    This seems to be fundamentally wrong., your variables are math so should be set in math italic $u$ not text italic (\textit{u}) and certainly not as emphasis (which is usualy italic but could be any other styling depending on the class and context (\emph{u}) – David Carlisle Dec 20 '15 at 13:45
  • 4
    use \varu\ or \varu{} to get space after the command name. – David Carlisle Dec 20 '15 at 13:46
5

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}
3
\usepackage{xspace}
\newcommand\varu{$u$\xspace}
1

LaTeX ignores the white spaces after commands. To ensure you get a space when you want it, use \varu\ . i.e. add a backslash before the space.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.