LaTeX:避免新段落?
我使用 \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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我必须同意其他人的观点,您可能应该只添加
%
,但我确实发现这个问题很有趣。问题是,一旦 LaTeX 读取空行,它就会转换为\par
命令,从而结束上一段。在\todo
的开头,该\par
命令已经被执行,并且不可能撤消它(我认为)。因此,您唯一的希望是防止\par
被插入或像平常那样表现。如果你想阻止它被插入,你可以尝试阅读《The TeXbook》的第 8 章,它应该告诉你如何将空行转换为\par
。或者,您可以尝试根据以下想法制定解决方案:但是要小心!你绝对不想全局改变
\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: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.当宏位于不需要的空格之前时,如果使用 \@ifnextchar 和 \@gobble,则不需要 %。
考虑类似的东西(当然,在序言中):
这样,如果您有类似的东西:
相同的作用
它将起到与or
您可以使用像这样的宏来概括这样的东西
然后您可以使用
\gobblepars
任何你想吃的地方(比如待办事项之后)。您还可以重新定义 todo(如上所示)以自动在其后面放置\gobblepars
。处理前导空白。您也可以使用
\gobblepars
,但必须明确。例如:将阻止 \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):
That way, if you have something like:
it will act the same as
or
You can generalize such things with a macro like
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:will prevent a \par from showing up between the two lines.
试试这个:
Try this:
可能您不应该在文本和待办事项注释之间留下新行或只是对其进行评论
may be you shouldn't leave new line between the text and the todo note or just comment it
怎么样
How about
设置
\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.如何将所有仍需要完成的工作保留在 \def 标记内,然后在没有更多工作要做时将其删除并正确移至文档中?
例如,
查尔斯·狄更斯(Charles Dickens)的《两个城市的故事》(A Tale of Two Cities),
这还有一个额外的好处,就是在源字面上和
输出中都为您提供了 \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.
A Tale of Two Cities, by Charles Dickens
That has the added benefit of giving you a \listoftodos both in the source literally, and
in the output.
只需在文本中间包含 \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. . .