# Labelling commands for quick use

I have a certain command in LaTeX that I have used a lot in my current work:

{\bf y} # this creates a bold letter y


I want to create a shortcut e.g.

\by


that will automatically create a bold letter y. I have similar expressions I would like to simplify as my equations are getting pretty long. Any advice would be appreciated.

• Use a good editor with good shortcuts if you want to speed up your editing, don't write unreadble code. New LaTeX macros are useful to keep consistency throughout your documents, not to avoid typing. Aug 9, 2013 at 14:36
• Please throw away your LaTeX documentation: \bf has been deprecated for two decades now. Aug 9, 2013 at 20:55

This is done with \newcommand, i.e.:

\newcommand{\by}{\textbf{y}}


There is more functionality in it than just substituting, i.e., you can have arguments there. Please find more info and some examples here.

• Cheers, that's great!
– Jonny Phelps
Aug 9, 2013 at 14:14
• Problem I'm having is that when I write $\by x$ I get both the y and the x as bold. Any way to resolve this and only have the y bold?
– Jonny Phelps
Aug 9, 2013 at 14:28
• Just put it in brackets, as edited. \bf is actually deprecated, so use \textbf instead Aug 9, 2013 at 14:31
• If the command is to be used in math mode, perhaps \mathbf{y} is preferable. Aug 9, 2013 at 21:39

\newcommand is the command you look for (see sashkello answer)

There are some things you should look for:

\documentclass{scrartcl}
\newcommand{\by}{\textbf{y}}

\begin{document}
Now we write a \by and a x.
\end{document}


The y is direct connected to the and.

You may add a space in \newcommand to add a space before the and:

\documentclass{scrartcl}

\newcommand{\by}{\textbf{y} } %<- space before the closing }

\begin{document}
Now we write a \by and a x.

Now we write a \by. The next sentence.

\end{document}


The next problem: There is an additional space when you start a new sentence.

For this problem you may use \xspace:

\documentclass{scrartcl}
\usepackage{xspace}

\newcommand{\by}{\textbf{y}\xspace}

\begin{document}
Now we write a \by and a x.

Now we write a \by. The next sentence.

\end{document}


The result: