使巨集遵守間距或缺少間距

使巨集遵守間距或缺少間距

我做了這個簡單的巨集:

\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}

是否可以告訴巨集檢查前面的空格(或字元)並遵守它,就像我\textbf{Q}正常鍵入一樣?我希望它能夠正常運行,無論前面是否有點(.)或空格()。

答案1

即使最近這種想法已經成為禁忌,但xspacepacakge 卻做到了這一點:

在此輸入影像描述

代碼:

\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}

相關內容