2010-02-13 28 views
4

使用LyX我試圖將「評論」轉換爲「邊緣筆記」。乳膠:將「評論」轉換爲「邊緣筆記」

我嘗試了幾件事情,但沒有運氣。

最好的拍攝是這樣的:

\makeatletter

\@ifundefined{comment}{}{%

\renewenvironment{comment}[1]%

{\begingroup\marginpar{\bgroup#1\egroup}}%

{\endgroup}}

\makeatother

或像這樣:

\@ifundefined{comment}{}{%

\renewenvironment{comment}%

{\marginpar{}%

{}}%

但我得到的是隻有轉換的文本的第一個字符。這樣的形象在:

IMAGE MARGINAL NOTE

我搜索了很多試圖找到如何解決這一點,但沒有運氣。我發現發生了什麼事的解釋:

意外輸出 只有一個角色是在新的字體 你以爲你改變字體在選定的文本,但只有第一個字符在新的字體已經出來了。 您最有可能使用了命令而不是聲明。該命令應該將文本作爲其參數。如果您不對文本進行分組,則只有第一個字符會作爲參數傳遞。

我不知道也無法找到的是如何分組文本。

希望有人能幫助我:-)

非常感謝。

最好的問候,

迭戈 (diegostex)

回答

5

好吧,讓我們通過你的(第​​一)重新定義走走看看發生了什麼:

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 

這裏的乳膠是怎麼想約你告訴它:

\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} 

然後乳膠會第一令牌作爲強制性論據。在這種情況下,第一個令牌是T,這是環境內容的第一個字符。因此,字母T將被放入頁邊空白中,其餘部分將顯示在正常段落中。

好吧,爲了達到我們想要的效果,comment環境不需要任何參數。我們要做的是創建一個框,將環境內容放入該框中,然後將該框放在邊框中。在我們開始之前,如果您將此代碼包含在文檔的前言中,則需要將它們全部包裝在\makeatletter\makeatother中,因爲我們將在其中使用帶有符號(@)的命令名。

首先,讓我們創建一個盒子把材料儲存在:

\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} 
+0

嗨Godbyk,優秀!!!!非常感謝它正是我所需要的。 此外,非常感謝您花時間詳細解釋這個問題,它幫助我瞭解正在發生的事情以及如何使用該框來存儲文本。我可以使用它的很多新的技巧:-)))) 乾杯, 迭戈 – diegos 2010-02-14 02:18:12

+0

我很高興它幫助。我認爲你的問題歸結爲對'\ renewenvironment'命令如何工作的輕微誤解;當我第一次遇到它時,它也拋出了一點,因爲環境的內容沒有被'#1'指定 - 相反,你只需要在'環境內容'命令和'環境內容'命令之前寫'。 – godbyk 2010-02-14 09:39:12

+0

不錯的工作;我不知道'{lrbox}'。 +1 – 2010-02-14 16:16:16

4

我想你想要的是一個宏觀的,而不是環境。 這是我一直使用的東西。宏定義:

\def\remark#1{\marginpar{\raggedright\hbadness=10000 
    \def\baselinestretch{0.8}\tiny 
    \it #1\par}} 

樣品用途:適用於一些合作者

\remark{Interesting comparisons with the 
    internal language of \citet{harper:type-theoretic}} 

我所做的變化,例如,\remark在它標記的文字中留下一個小小的固定寬度的鑽石。

+0

諾曼,非常感謝您的及時答覆。 是的,我也使用類似的東西,但特別是我想重新定義「評論」環境的邊緣筆記,因爲我希望能夠使用LyX內的「搜索下一個音符」,並打印評論這樣他們就不會改變正文的流程。 我認爲唯一的方法是更新評論環境,但我不知道如何將評論文本分組,所以我可以將其全部轉換而不是第一個字母。 – diegos 2010-02-14 02:05:08

+0

@diagos:我看到'{lrbox}'環境是這個故事的英雄。好工作@godbyk! – 2010-02-14 16:14:11

1

我用LyX的評論以同樣的方式,發現了以下解決方案:

\usepackage{environ} 
\let\comment\relax% removes and previous definition of \begin{comment} 
\let\endcomment\relax% removes any previous definition of \end{comment} 
\NewEnviron{comment}{\marginpar{\BODY}}