4

LyX を使用して、「コメント」を「限界メモ」に変換しようとしています。

私はいくつかのことを試しましたが、運がありませんでした。

ベストショットはこんな感じ。

\makeatletter

\@ifundefined{comment}{}{%

\renewenvironment{comment}[1]%

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

{\endgroup}}

\makeatother

またはこのように:

\@ifundefined{comment}{}{%

\renewenvironment{comment}%

{\marginpar{}%

{}}%

しかし、私が得るのは、変換されたテキストの最初の文字だけです。この画像のように:

画像限界注記

これを解決する方法を見つけようとして多くを検索しましたが、運がありませんでした。何が起こっているのかの説明を見つけました:

予期しない出力 新しいフォントに 1 文字しかない 選択したテキストのフォントを変更したと思ったら、最初の文字だけが新しいフォントになっています。宣言の代わりにコマンドを使用した可能性があります。このコマンドは、テキストを引数として受け取る必要があります。テキストをグループ化しない場合、最初の文字のみが引数として渡されます。

私が知らない、見つけることができなかったのは、テキストをグループ化する方法です。

誰かが私を助けてくれることを願っています:-)

どうもありがとう。

よろしくお願いします、

ディエゴ (diegostex)

4

3 に答える 3

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

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 は最初のトークンを必須の引数として受け取ります。この場合、最初のトークンはT、環境コンテンツの最初の文字です。そのため、文字Tは余白に配置され、残りのテキストは通常​​の段落に表示されます。

さて、私たちが望むものを達成するために、comment環境は引数を必要としません。ボックスを作成し、環境の内容をそのボックスに入れ、そのボックスを余白に配置します。

開始する前に、このコードをドキュメントのプリアンブルに含める場合は、すべてをラップする必要があります\makeatletter。これは、名前に\makeatotherアットマーク ( ) を含むコマンドを使用するためです。@

まず、マテリアルを格納するボックスを作成しましょう。

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

次に、comment環境の定義を開始します。環境の begin コマンドと end コマンドを に設定します\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}
于 2010-02-13T22:32:30.200 に答える
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それがマークするテキストに小さな固定幅のひし形を残します。

于 2010-02-13T20:03:25.060 に答える
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}}
于 2011-02-19T23:37:06.840 に答える