Latex: Convert Commentary to Marginal Note

using LyX I am trying to convert "comments" into "marginal notes".

I tried a few things but no luck.

The best shot was like this:

\makeatletter

\@ifundefined{comment}{}{%

\renewenvironment{comment}[1]%

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

{\endgroup}}

\makeatother

or like this:

\@ifundefined{comment}{}{%

\renewenvironment{comment}%

{\marginpar{}%

{}}%

But I get only the first character of the converted text. As in this image:

PICTURE PICTURE

I searched a lot, trying to find how to solve this, but without any luck. I found an explanation of what was happening:

Unexpected result. In the new font, only one character. You thought that you changed the font to choose the text, but only the first character appeared in the new font. You most likely used a command instead of an ad. The team should take the text as an argument. If you do not group the text, only the first character will be passed as an argument.

What I do not know and could not find is how to group the text.

Hope someone can help me :-)

Many thanks.

Best wishes,

Diego (Diegostex)

+4
source share
3 answers

Ok, let me go through your (first) redefinition to see what happens:

 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 

Here's how LaTeX thinks about what you told him:

 \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 

Note that xyzzy is a required argument ( #1 ). The contents of the medium (" This is the ...") are inserted between lines 3 and 4.

If you write the following in your document:

 \begin{comment}% <-- missing mandatory argument This is the contents of the environment. \end{comment} 

Then LaTeX will take the first token as a required argument. In this case, the first token is T , the first character of the contents of the medium. Thus, the letter T will be placed in the field, and the rest of the text will be displayed in a regular paragraph.

So, in order to achieve what you want, the comment environment does not need any arguments. What we will do is create a field, put the contents of the environment into it, and then put this field in the field.

Before we begin, if you include this code in the preamble of the document, you will need to wrap it all in \makeatletter and \makeatother , since we will use commands with signs ( @ ) in their names.

First create a field to store the material in:

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

Then we will start defining the comment environment. We set the start and end commands of the environment to \relax . This way our \newenvironment team will be guaranteed.

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

From this perspective, we can define our new comment environment:

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

Now in your document you can enter:

 \begin{comment} This is a comment that gets printed in the margin. \end{comment} 

So, just for the convenience of copying and pasting, what a complete document looks like:

 \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} 
+5
source

I think what you want is a macro, not an environment. Here is what I use all the time. Macro Definition:

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

Using an example:

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

I made variations for some collaborators, for example, \remark leaves a tiny fixed-width diamond in the text that it notes.

+4
source

I use LyX comments in the same way and found the following solution:

 \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}} 
+1
source

Source: https://habr.com/ru/post/1301208/


All Articles