LaTeX:避免新段落?

发布于 2024-08-02 17:28:14 字数 340 浏览 11 评论 0原文

我使用 \todonotes 包中的 \todo 命令。我想布局我的源代码,将 \todos 与上一段分开:

Some text.

\todo{make note}

但我不希望 \todo 开始一个新段落,否则会搞砸文档的间距。

有没有命令可以避免这种情况?

如果有一个命令/包来消耗它之前的空白,那么我可以重新定义 \todo 来使用它。

编辑:在所有内容之间添加%显然非常令人恼火。还要别的吗?

I use the \todo command from the \todonotes package. I'd like to layout my source to put \todos separately from the previous paragraph:

Some text.

\todo{make note}

But I don't want \todo to start a new paragraph, or it screws up the spacing of the document.

Is there a command to avoid this?

If there were a command/package to consume the whitespace up to it, then I could redefine \todo to use it.

Edit: Adding a % between everything is obviously very irritating. Anything else?

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

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

发布评论

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

评论(8

嘿咻 2024-08-09 17:28:14

我必须同意其他人的观点,您可能应该只添加 %,但我确实发现这个问题很有趣。问题是,一旦 LaTeX 读取空行,它就会转换为 \par 命令,从而结束上一段。在 \todo 的开头,该 \par 命令已经被执行,并且不可能撤消它(我认为)。因此,您唯一的希望是防止 \par 被插入或像平常那样表现。如果你想阻止它被插入,你可以尝试阅读《The TeXbook》的第 8 章,它应该告诉你如何将空行转换为 \par。或者,您可以尝试根据以下想法制定解决方案:

Some text.{\let\par\relax

\todo{make note}}

但是要小心!你绝对不想全局改变\par的行为,这就是为什么我添加了一对额外的花括号(LaTeX命令是有作用域的,所以新的定义\par 仅在定义所在的组内生效)。祝你好运。

I have to agree with everybody else that you should probably just add the %, but I do find this question interesting. The problem is that as soon as LaTeX reads the empty line, it gets converted into the \par command, which ends the previous paragraph. At the beginning of \todo, that \par command has already been executed, and it's impossible to undo it (I think). So your only hope is to keep that \par from being inserted or from behaving like it normally does. If you want to prevent it from being inserted, you could try reading Chapter 8 of "The TeXbook", which should tell you how an empty line is converted to \par. Alternatively, you could try to make a solution based on the following kind of idea:

Some text.{\let\par\relax

\todo{make note}}

But watch out! You definitely don't want to globally change the behavior of \par, which is why I added an extra pair of curly braces (LaTeX commands are scoped, so the new definition of \par only takes effect within the group where the definition was made). Good luck.

阿楠 2024-08-09 17:28:14

当宏位于不需要的空格之前时,如果使用 \@ifnextchar 和 \@gobble,则不需要 %。

考虑类似的东西(当然,在序言中):

\makeatletter
\let\oldtodo\todo
\renewcommand\todo[1]{%
\oldtodo{#1}%
\@ifnextchar\par{\@gobble}{}}
\makeatother

这样,如果您有类似的东西:

\todo{Stuff}

Things

相同的作用

\todo{Stuff}
%
Things

它将起到与or

\todo{Stuff}
Things

您可以使用像这样的宏来概括这样的东西

\makeatletter
\newcommand\gobblepars{%
    \@ifnextchar\par%
        {\expandafter\gobblepars\@gobble}%
        {}}
\makeatother

然后您可以使用 \gobblepars任何你想吃的地方(比如待办事项之后)。您还可以重新定义 todo(如上所示)以自动在其后面放置 \gobblepars

处理前导空白。您也可以使用 \gobblepars,但必须明确。例如:

Some text\gobblepars

\todo{Stuff}

将阻止 \par 出现在两行之间。

When the macro precedes the unwanted space, the % is not necessary if you make use of \@ifnextchar and \@gobble.

Consider something like (in the preamble, of course):

\makeatletter
\let\oldtodo\todo
\renewcommand\todo[1]{%
\oldtodo{#1}%
\@ifnextchar\par{\@gobble}{}}
\makeatother

That way, if you have something like:

\todo{Stuff}

Things

it will act the same as

\todo{Stuff}
%
Things

or

\todo{Stuff}
Things

You can generalize such things with a macro like

\makeatletter
\newcommand\gobblepars{%
    \@ifnextchar\par%
        {\expandafter\gobblepars\@gobble}%
        {}}
\makeatother

You can then use \gobblepars wherever you want to eat space (like after the todo). You can also re-define todo (as shown above) to automatically place a \gobblepars after it.

To handle the leading empty space. you can use \gobblepars too, but you have to be explicit. For example:

Some text\gobblepars

\todo{Stuff}

will prevent a \par from showing up between the two lines.

孤蝉 2024-08-09 17:28:14

试试这个:

Some text.
%
\todo{make note}

Try this:

Some text.
%
\todo{make note}
因为看清所以看轻 2024-08-09 17:28:14

可能您不应该在文本和待办事项注释之间留下新行或只是对其进行评论

Some text.
%
\todo{make note}

may be you shouldn't leave new line between the text and the todo note or just comment it

Some text.
%
\todo{make note}
戏舞 2024-08-09 17:28:14

怎么样

Some text.
%
\todo{make note}
%
some more text

How about

Some text.
%
\todo{make note}
%
some more text
我早已燃尽 2024-08-09 17:28:14

设置 \endlinechar=-1 使空行无效。您将需要使用 \par 来分隔段落,我认为这比在分隔行上键入 % 更让人恼火,但这就是您所要求的。

Set \endlinechar=-1 to make empty lines have no effect. You will need to use \par to separate paragraphs, which I think is a bigger irritation than having to type % on separator lines, but that's what you're asking for.

揽月 2024-08-09 17:28:14

如何将所有仍需要完成的工作保留在 \def 标记内,然后在没有更多工作要做时将其删除并正确移至文档中?

例如,

\def \par1
{
It was the best of times, it was the
}

\def \par2000
{
"Repression is the only lasting philosophy. The dark deference of fear and slavery, my friend," observed the Marquis
}

\def \paridunno
{
The end
}

查尔斯·狄更斯(Charles Dickens)的《两个城市的故事》(A Tale of Two Cities),

\par1
\todo{write a whole bunch of pages}
\par2000
\todo{Visit ghost of Christmas future, copy pages from finished book}
\paridunno
\todo{Think of a better ending}

这还有一个额外的好处,就是在源字面上和

输出中都为您提供了 \listoftodos 。

How about keeping everything that still has work left to do inside \def tags, and then removing it and moving it into the document proper when there's no more work to do?

E.g.

\def \par1
{
It was the best of times, it was the
}

\def \par2000
{
"Repression is the only lasting philosophy. The dark deference of fear and slavery, my friend," observed the Marquis
}

\def \paridunno
{
The end
}

A Tale of Two Cities, by Charles Dickens

\par1
\todo{write a whole bunch of pages}
\par2000
\todo{Visit ghost of Christmas future, copy pages from finished book}
\paridunno
\todo{Think of a better ending}

That has the added benefit of giving you a \listoftodos both in the source literally, and

in the output.

当梦初醒 2024-08-09 17:28:14

只需在文本中间包含 \todo 即可。没有换行,什么也没有。

等等等等文字\todo{现在就做这个!}更多文字等等等等。

在我的电脑(win xp、miktex 2.7、texniccenter)上,这个工作正常,不会产生换行符,并将待办事项注释放在页边空白处。 。 。

just include your \todo right in the middle of your text. no line break, no nothing.

blah blah blah text \todo{Do this now!} more text blah blah blah.

on my computer (win xp, miktex 2.7, texniccenter) this work fine, produces no line break, and puts the todo note in the margin. . .

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