0

Defining a new command as \newcommand{\boo}{\texttt{boo}} and then using it in the text as \boo removes the space after boo and the next word. This is fine if the next word happens to be a period, ., but not good otherwise.

The workout is to write \boo \ in the main text. Question: Is there a way to avoid this "\" (to be able to type faster)?

What I tried: I tried \newcommand{\boo}{\texttt{boo}\ } instead, but then the problem with the period is reversed - it is not fine if the next word happens to be period, ., but is fine otherwise.

bissi
  • 139
  • 3
    it is literally just one character so you could call your command bo instead of boo then it's the same again, really it is better to just use \ (or {} but see xspace package if you are not convinced. – David Carlisle Apr 08 '21 at 10:15
  • There is a human tendency (I'm guilty too) of wanting to save on keystrokes, in the name of "efficiency". But years of experience has shown that such an approach often results in later difficulty, either sharing the code with others, or trying to figure out what I was doing to begin with (what's with those cryptic macro names??!!). The phrase "penny wise and pound foolish" comes to mind. – Steven B. Segletes Apr 08 '21 at 10:24
  • @DavidCarlisle agreed. However, the true command is not boo of course, but something much longer. xspace helps. – bissi Apr 08 '21 at 10:34
  • @bissi so if it is already long why does one extra \ at the end make any difference to typing speed? See https://tex.stackexchange.com/a/86620/1090 – David Carlisle Apr 08 '21 at 10:36
  • @DavidCarlisle its an honor to have you comment on my post! – bissi Apr 08 '21 at 11:38

1 Answers1

2

To pick up on David Carlisle's comment: You can use the package xspace which has been created to handle such situations.

\documentclass{article}

\usepackage{xspace} \newcommand{\boo}{\texttt{boo}\xspace}

\begin{document}

This is \boo. This is also \boo and \boo again.

\end{document}

enter image description here

See also this discussion.