![典型错误:xspace 总是向前看,从不向后看](https://linux22.com/image/461062/%E5%85%B8%E5%9E%8B%E9%94%99%E8%AF%AF%EF%BC%9Axspace%20%E6%80%BB%E6%98%AF%E5%90%91%E5%89%8D%E7%9C%8B%EF%BC%8C%E4%BB%8E%E4%B8%8D%E5%90%91%E5%90%8E%E7%9C%8B%20.png)
我们如何解释这两个输出之间的差异,其中第二个输出}
紧随其后\xspace
?
平均能量损失
\documentclass{article}
\usepackage{xspace}
\usepackage[citestyle=authoryear]{biblatex}
\newcommand{\coolxspaceunprotected}{\ifhmode\unskip\xspace\fi}
\newcommand{\coolxspaceprotected}{{\ifhmode\unskip\xspace\fi}} % How to avoid the braces?
\newcommand{\spacetciteunprotected}{\coolxspaceunprotected\textcite}
\newcommand{\spacetciteprotected}{\coolxspaceprotected\textcite}
\begin{filecontents}{\jobname.bib}
@book{smith96,
author = {Smith, Adam},
year = {1996},
title = {Economy},
publisher = {My company}
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
\section{\spacetciteunprotected{smith96} and the blob hypothesis}
\section{\spacetciteprotected{smith96} and the blob hypothesis}
\end{document}
答案1
您的主要问题是您在 中添加了一个空格hmode
,但就在 parindent(或 sec number)框之后,您hmode
不想有空格。\xspace
在这里没有帮助。你想看看后退不是向前,这避免在(节点类型 1)之后添加空格,hbox
因此它会在字符之后添加空格。
\documentclass{article}
\usepackage[citestyle=authoryear]{biblatex}
\DeclareRobustCommand\coolspaceunprotected{%
\ifhmode\ifnum\lastnodetype=1 \else\unskip\unskip\space
\fi\fi}
\DeclareRobustCommand\spacetciteunprotected{\coolspaceunprotected\textcite}
\begin{filecontents}{\jobname.bib}
@book{smith96,
author = {Smith, Adam},
year = {1996},
title = {Economy},
publisher = {My company}
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
\tableofcontents
\section{\spacetciteunprotected{smith96} and the blob hypothesis}
a
\section{\textcite{smith96} and the blob hypothesis}
b
\section{Foo,\spacetciteunprotected{smith96} and the blob hypothesis}
c
\section{Foo,\textcite{smith96} and the blob hypothesis}
d
\end{document}