die*_*gos 4 latex comments lyx
使用LyX我试图将"评论"转换为"边缘笔记".
我尝试了几件但没有运气.
最好的镜头是这样的:
\makeatletter
\@ifundefined{comment}{}{%
\renewenvironment{comment}[1]%
{\begingroup\marginpar{\bgroup#1\egroup}}%
{\endgroup}}
\makeatother
或者像这样:
\@ifundefined{comment}{}{%
\renewenvironment{comment}%
{\marginpar{}%
{}}%
但我得到的只是转换文本的第一个字符.就像在这张图片中:
我搜索了很多试图找到如何解决这个但没有运气.我找到了正在发生的事情的解释:
意外输出新字体中只有一个字符您认为您在选择的文本上更改了字体,但只有第一个字符以新字体显示.您最有可能使用命令而不是声明.该命令应该以文本作为参数.如果不对文本进行分组,则只将第一个字符作为参数传递.
我不知道并且无法找到的是如何对文本进行分组.
希望有人能帮助我:-)
非常感谢.
最好的祝福,
迭戈(diegostex)
好的,让我们逐步完成你的(第一次)重新定义,看看发生了什么:
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
Run Code Online (Sandbox Code Playgroud)
以下是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
Run Code Online (Sandbox Code Playgroud)
注意,这xyzzy是必需参数(#1).环境内容(" This is the...")插入第3行和第4行之间.
如果您在文档中写下以下内容:
\begin{comment}% <-- missing mandatory argument
This is the contents of the environment.
\end{comment}
Run Code Online (Sandbox Code Playgroud)
然后LaTeX将第一个标记作为强制参数.在这种情况下,第一个标记是T环境内容的第一个字符.所以这封信T将放在保证金中,文本的其余部分将显示在正常的段落中.
好的,为了实现我们想要的,comment环境不需要任何参数.我们要做的是创建一个框,将环境内容放在该框中,然后将该框放在边框中.
在我们开始之前,如果您将此代码包含在文档的前导码中,则需要将其全部包含在内\makeatletter,\makeatother因为我们将使用@名称中带有sign()的命令.
首先,让我们创建一个框来存储材料:
\newsavebox{\marginbox}% contains the contents of the comment environment
Run Code Online (Sandbox Code Playgroud)
接下来,我们将开始定义comment环境.我们将环境开始和结束命令设置为\relax.这样我们的\newenvironment命令将保证有效.
\let\comment\relax% removes and previous definition of \begin{comment}
\let\endcomment\relax% removes any previous definition of \end{comment}
Run Code Online (Sandbox Code Playgroud)
有了这个,我们可以定义我们的新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
}
Run Code Online (Sandbox Code Playgroud)
现在,在您的文档中,您可以键入:
\begin{comment}
This is a comment that gets printed in the margin.
\end{comment}
Run Code Online (Sandbox Code Playgroud)
所以只是为了便于复制和粘贴,这是一个完整的文档看起来像:
\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}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1741 次 |
| 最近记录: |