在乳胶中定义宏 \etc \ie 的正确方法

发布于 2024-09-10 04:32:51 字数 522 浏览 2 评论 0原文

这篇文章作者讨论了使用\@来放置正确的句号后的空格不在句子末尾,例如 Mr. ie 等。

建议的宏

\newcommand\etc{etc\@ifnextchar.{}{.\@}}

并不十分完美,因为在 (\etc more text) 的情况下它会生成 (etc .更多文字)

我见过很多作者制作了自己的 \etc 宏版本,大部分是 etc.\ 的变体。

\etc\ie\etal\eg 的哪些宏在大多数情况下会产生最好的结果?

这是不是太个人化了,无法普遍解决?

In
this article the author discusses the use of \@ to put correct spacings after full stops that are not at the end of a sentence e.g. Mr. i.e. etc.

The macro suggested

\newcommand\etc{etc\@ifnextchar.{}{.\@}}

is not quite perfect since in the case (\etc more text) it produces (etc.more text).

I have seen a lot of authors who have made their own versions of the \etc macro, mostly variations on etc.\.

What macros for \etc, \ie, \etal, \eg produce the nicest results in the most situations?

Is this something too personal in taste to be solved in general?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

往日情怀 2024-09-17 04:32:51

早些时候,我使用宏来表示“et al.”等,但现在我会阻止人们定义此类宏。

一个问题是您已经观察到的:要获得正确的定义以便它们正确处理所有特殊情况(包括与其他包的交互 - 例如,那些重新定义“\cite”命令并调整引用之前的间距的包,这是非常棘手的) )。

但更重要的是,即使有一堆适合您需求的宏,并且您知道如何使用它们,您的共同作者也可能对具体如何使用它们感到困惑在各种特殊情况下正确使用宏。

因此,我建议您避免使用宏来处理诸如“et al”之类的琐碎事情。并使用标准 Latex 标记简单地拼出所有内容。毕竟,大多数情况不需要任何特殊处理(“eg”后面经常跟逗号;“et al.”后面经常跟“~\cite”等),而每当需要特殊处理时,所有Latex 用户应该知道如何使用“\”和“\@”等命令。

Earlier I used macros for "et al.", etc., but nowadays I would discourage people from defining that kind of macros.

One problem is what you already observed: it's surprisingly tricky to get the definitions right so that they handle all special cases correctly (including the interactions with other packages – e.g., those that re-define the "\cite" command and tweak spacing before references).

But more importantly, even if you have a bunch of macros that suit your needs and you know how to use them, your co-authors are likely to be confused with exactly how to use your macros correctly in various special cases.

Hence I'd recommend that you avoid macros for trivial things such as "et al." and simply spell out everything by using standard Latex markup. After all, most cases don't need any special handling ("e.g." is often followed by a comma; "et al." is often followed by "~\cite", etc.), and whenever special handling is needed, all Latex users should know how to use commands such as "\ " and "\@".

稀香 2024-09-17 04:32:51

在CVPR的样式包中,定义为:

\usepackage{xspace}

% Add a period to the end of an abbreviation unless there's one
% already, then \xspace.
\makeatletter
\DeclareRobustCommand\onedot{\futurelet\@let@token\@onedot}
\def\@onedot{\ifx\@let@token.\else.\null\fi\xspace}

\def\eg{\emph{e.g}\onedot} \def\Eg{\emph{E.g}\onedot}
\def\ie{\emph{i.e}\onedot} \def\Ie{\emph{I.e}\onedot}
\def\cf{\emph{c.f}\onedot} \def\Cf{\emph{C.f}\onedot}
\def\etc{\emph{etc}\onedot} \def\vs{\emph{vs}\onedot}
\def\wrt{w.r.t\onedot} \def\dof{d.o.f\onedot}
\def\etal{\emph{et al}\onedot}
\makeatother

In CVPR's style package, it is defined as:

\usepackage{xspace}

% Add a period to the end of an abbreviation unless there's one
% already, then \xspace.
\makeatletter
\DeclareRobustCommand\onedot{\futurelet\@let@token\@onedot}
\def\@onedot{\ifx\@let@token.\else.\null\fi\xspace}

\def\eg{\emph{e.g}\onedot} \def\Eg{\emph{E.g}\onedot}
\def\ie{\emph{i.e}\onedot} \def\Ie{\emph{I.e}\onedot}
\def\cf{\emph{c.f}\onedot} \def\Cf{\emph{C.f}\onedot}
\def\etc{\emph{etc}\onedot} \def\vs{\emph{vs}\onedot}
\def\wrt{w.r.t\onedot} \def\dof{d.o.f\onedot}
\def\etal{\emph{et al}\onedot}
\makeatother
陌上芳菲 2024-09-17 04:32:51

您是否尝试过使用 xspace 包?

示例宏:

\def\etc{etc.\@\xspace}

一些测试:

猫、狗等。等等。 \\
猫、狗等!等等。 \\
猫、狗等。 \\
猫(狗,\等)。等等。 \\

产品:

alt text


来自 文档

xspace 包提供了一个
查看后面的命令
它在命令流中,并决定
是否插入空格替换
被 TeX 命令“吃掉”的一个
解码器。

Have you tried using the xspace package?

Example macro:

\def\etc{etc.\@\xspace}

Some tests:

Cat, dog, \etc. And so on.   \\
Cat, dog, \etc! And so on.   \\
Cat, dog, \etc, and so on.   \\
Cat (dog, \etc). And so on.  \\

Produces:

alt text


From the documentation:

The xspace package provides a single
command that looks at what comes after
it in the command stream, and decides
whether to insert a space to replace
one "eaten" by the TeX command
decoder.

神也荒唐 2024-09-17 04:32:51

技术挑战!我们可以通过查看下一个字符的catcode并查看它是否是字母来避免空格后字母的问题;这可以使用 Latex3 的 expl3 宏 \peek_charcode:NTF 来完成(我的第一个 expl3 代码!):

\documentclass{article}

\usepackage{expl3}
\ExplSyntaxOn
\newcommand\latinabbrev[1]{
  \peek_meaning:NTF . {% Same as \@ifnextchar
    #1\@}%
  { \peek_catcode:NTF a {% Check whether next char has same catcode as \'a, i.e., is a letter
      #1.\@ }%
    {#1.\@}}}
\ExplSyntaxOff

%Omit final dot from each def.
\def\eg{\latinabbrev{e.g}}
\def\etal{\latinabbrev{et al}}
\def\etc{\latinabbrev{etc}}
\def\ie{\latinabbrev{i.e}}

\begin{document}

Maybe a list, \eg, a, b, c, and d.  Which is to say (\ie) a, b, \etc.  Consider Knuth, \cf The TeXbook.

\end{document}

不过,我认为 Jukka 的建议是合理的:我想说这个问题将与他的 \etc 一起解决我们应该将这个宏视为 Tex 的双倍行距实现中的一个错误(Will Robertson 应该索要他的支票):如果您知道存在该错误,您可以通过在诸如“.)”之类的情况下输入 \@ 来直接解决它,或者你可能有棘手的代码,这意味着你不必在这种情况下思考,但你增加了排版方式的复杂性,这对于你来说不会在下一个意外故障(你可能已经介绍过)中起作用。

Postscript 先前版本已修复,感谢约瑟夫·赖特 (Joseph Wright) 在 tex.stackexchange.com 上注意到一个愚蠢的错误

A technical challenge! We can avoid the problem of letters after spaces by looking at the catcode of the next character and seeing whether or not it is a letter; this can be done with the Latex3's expl3 macro \peek_charcode:NTF (my first expl3 code!):

\documentclass{article}

\usepackage{expl3}
\ExplSyntaxOn
\newcommand\latinabbrev[1]{
  \peek_meaning:NTF . {% Same as \@ifnextchar
    #1\@}%
  { \peek_catcode:NTF a {% Check whether next char has same catcode as \'a, i.e., is a letter
      #1.\@ }%
    {#1.\@}}}
\ExplSyntaxOff

%Omit final dot from each def.
\def\eg{\latinabbrev{e.g}}
\def\etal{\latinabbrev{et al}}
\def\etc{\latinabbrev{etc}}
\def\ie{\latinabbrev{i.e}}

\begin{document}

Maybe a list, \eg, a, b, c, and d.  Which is to say (\ie) a, b, \etc.  Consider Knuth, \cf The TeXbook.

\end{document}

Jukka's advice I think is sound, though: I'd say the problem Will works around with his \etc macro we should see as a bug in Tex's implementation of double spacing (Will Robertson should ask for his cheque): if you know the bug is there, you can workaround it directly by putting in \@ in cases such as ".)", or you can have tricky code that means you don't have to think in this case, but you have added complexity to the way you typeset which is not going to work for you with the next unexpected glitch, one you probably have introduced yourself.

Postscript Previous version fixed, thanks to Joseph Wright noticing a stupid error at tex.stackexchange.com.

执笔绘流年 2024-09-17 04:32:51

所有 LaTeX 命令都消除了后面的空格。如果你想要一个空格,你需要转义它:

\etc\ and more

这是必要的,因为你需要清楚命令名在哪里结束。 \etcno space 无法正确解释。

All LaTeX commands eliminate space after them. If you want a space, you need to escape it:

\etc\ and more

This is necessary, because you need to be clear where the command name ends. \etcno space cannot be correctly interpreted.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文