2

I made this simple macro:

\documentclass{ltxdoc}
\newcommand\Q{\textbf{Q}}

\begin{document}
I like to type my \Q's in bold quickly, but sometimes I also end my line with \Q. 
This doesn't have it's intended effect.
\end{document}

Is it possible to tell the macro to check the space (or character) ahead and obey it as if I typed \textbf{Q} normally? I'd like it to behave normally regardless of whether there's a dot (.) or a whitespace ( ) ahead.

1010011010
  • 6,357
  • No the space is the delimiter of the macro name. There is xspace but see http://tex.stackexchange.com/a/86620/1090 – David Carlisle May 08 '14 at 15:14
  • I just get in the habit of typing its use case as {\Q} in my document. Then it acts the way you want. – Steven B. Segletes May 08 '14 at 15:37
  • 2
    {\Q} would disable the automatic italic correction insertion that is added by \text... commands (or at least it would disable it on the right but not on the left) probably more of an issue with \textit than \texbf but still.... – David Carlisle May 08 '14 at 15:49
  • Can you add some examples of the input and the desired output as I don't seem to be getting exactly what is desired behavior is. – Peter Grill May 08 '14 at 16:56
  • @PeterGrill I'd like to see {}{} instead of {}{}{>dot>} when using \Q. That's all I ask for. – 1010011010 May 08 '14 at 17:32
  • Please add these examples to the question. With the xspace solution \Q. does produce {<bold Q>}{<dot>} without a space, but so did the MWE you had posted originally. Does this one example cover all the cases you are considering? – Peter Grill May 08 '14 at 17:37
  • @PeterGrill Package xspace didn't produce the desired result in my document, so I think I'll just go with a 1% less cleaner code of the main document. I could go over each and every case, but I don't think either of us would enjoy it. Thanks for your answers and help :) – 1010011010 May 08 '14 at 17:48

1 Answers1

1

Even thought is has sort of become taboo lately, the xspace pacakge does that:

enter image description here

Code:

\documentclass{ltxdoc}
\usepackage{xspace}
\newcommand\Q{\textbf{Q}\xspace}

\begin{document} I like to type my \Q's in bold quickly, but sometimes I also end my line with \Q. This doesn't have it's intended effect.

In a sentence \Q works now. \end{document}

Peter Grill
  • 223,288
  • 2
    well it does something but it doesn't do what was asked. It is not possible to check if there was space or not; xspace adds space depending on whether there is following punctuation but any space is not seen \Q . is the same as \Q. as the space is gone before \Q is even recognised. – David Carlisle May 08 '14 at 15:22
  • @DavidCarlisle Ah, the subtle weakness of xspace… Luckily having \Q . blah is bad form :) – Sean Allred May 08 '14 at 15:35
  • @DavidCarlisle: Hmmm. Wonder if I got into the habit of not reading the question from someone who doesn't think it is fair to read documentation. :-) Guess I am not understanding the question fully. – Peter Grill May 08 '14 at 16:54