gpt4 book ai didi

latex :将 "Comment"转换为 "Marginal Note"

转载 作者:行者123 更新时间:2023-12-04 22:52:41 25 4
gpt4 key购买 nike

使用 LyX 我试图将“评论”转换为“边注”。

我尝试了几件事,但没有运气。

最好的镜头是这样的:
\makeatletter\@ifundefined{comment}{}{%\renewenvironment{comment}[1]%{\begingroup\marginpar{\bgroup#1\egroup}}%{\endgroup}}\makeatother
或者像这样:
\@ifundefined{comment}{}{%\renewenvironment{comment}%{\marginpar{}%{}}%
但我得到的只是转换后的文本的第一个字符。就像这张图片:

IMAGE MARGINAL NOTE

我搜索了很多试图找到如何解决这个问题但没有运气。我找到了对正在发生的事情的解释:

Unexpected Output Only one character is in the new font You thought you changed font over a selection of text, but only the first character has come out in the new font. You have most probably used a command instead of a declaration. The command should take the text as its argument. If you don't group the text, only the first character will be passed as the argument.



我不知道也无法找到的是如何对文本进行分组。

希望有人可以帮助我:-)

非常感谢。

此致,

迭戈
(地高斯泰克斯)

最佳答案

好的,让我们来看看你的(第一个)重新定义,看看发生了什么:

1   \@ifundefined{comment}{}{% only do this if the comment environment has been defined
2 \renewenvironment{comment}[1]% redefining a 'comment' environment with one mandatory argument
3 {\begingroup\marginpar{\bgroup#1\egroup}}% put the mandatory argument inside a marginpar
4 {\endgroup}}% close the environment

以下是 LaTeX 如何思考您所说的内容:
\begin{comment}{xyzzy}% <-- note the mandatory argument (runs line 3)
This is the contents of the environment.
\end{comment}% <-- this is where LaTeX runs line 4

请注意 xyzzy是强制性参数 ( #1 )。环境的内容(“ This is the ...”)被插入到第 3 行和第 4 行之间。

如果您在文档中写入以下内容:
\begin{comment}% <-- missing mandatory argument
This is the contents of the environment.
\end{comment}

然后 LaTeX 将第一个标记作为强制参数。在这种情况下,第一个 token 是 T , 环境内容的第一个字符。所以信 T将放在页边空白处,文本的其余部分将显示在正常段落中。

好的,为了实现我们想要的, comment环境不需要任何参数。我们要做的是创建一个框,将环境的内容放入该框中,然后将该框放置在边距中。

在我们开始之前,如果您将此代码包含在文档的序言中,则需要将其全部包装在 \makeatletter 中。和 \makeatother因为我们将使用名称中带有 at 符号 ( @ ) 的命令。

首先,让我们创建一个盒子来存储 Material :
\newsavebox{\marginbox}% contains the contents of the comment environment

接下来,我们将开始定义 comment环境。我们将环境开始和结束命令设置为 \relax .这样我们的 \newenvironment命令将保证工作。
\let\comment\relax% removes and previous definition of \begin{comment}
\let\endcomment\relax% removes any previous definition of \end{comment}

有了这个,我们可以定义我们的新 comment环境:
\newenvironment{comment}{%
\begin{lrbox}{\marginbox}% store the contents of the environment in a box named \marginbox
\begin{minipage}{\marginparwidth}% create a box with the same width as the marginpar width
\footnotesize% set any font or other style changes you'd like
}{% the following lines are for the \end{comment} command
\end{minipage}% close the minipage
\end{lrbox}% close the box
\marginpar{\usebox{\marginbox}}% typeset the box in the margin
}

现在,在您的文档中,您可以输入:
\begin{comment}
This is a comment that gets printed in the margin.
\end{comment}

因此,为了便于复制和粘贴,完整的文档如下所示:
\documentclass{article}

\makeatletter

\newsavebox{\marginbox}% contains the contents of the comment environment

\let\comment\relax% removes and previous definition of \begin{comment}
\let\endcomment\relax% removes any previous definition of \end{comment}

\newenvironment{comment}{%
\begin{lrbox}{\marginbox}% store the contents of the environment in a box named \marginbox
\begin{minipage}{\marginparwidth}% create a box with the same width as the marginpar width
\footnotesize% set any font or other style changes you'd like
}{% the following lines are for the \end{comment} command
\end{minipage}% close the minipage
\end{lrbox}% close the box
\marginpar{\usebox{\marginbox}}% typeset the box in the margin
}

\makeatother

\usepackage{lipsum}% just provides some filler text

\begin{document}

Hello, world!
\begin{comment}
This is a comment that gets printed in the margin.
\end{comment}
\lipsum

\end{document}

关于 latex :将 "Comment"转换为 "Marginal Note",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2258669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com