using LyX I’m trying to convert the “comments” into “marginal notes”.
I tried several things but without 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 what I get is only the first character of the text converted. Like in this image:
I searched a lot trying to find how to solve this but without luck. I found the explanation of what is happening:
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.
What I don’t know and wasn’t able to find is how to group the text.
Hope someone could help me 🙂
Many thanks.
Best Regards,
Diego
(diegostex)
Okay, let’s walk through your (first) redefinition to see what’s happening:
Here’s how LaTeX is thinking about what you’ve told it:
Note that
xyzzyis the mandatory argument (#1). The contents of the environment (“This is the…”) are inserted between lines 3 and 4.If you write the following in your document:
Then LaTeX will take the first token as the mandatory argument. In this case, the first token is
T, the first character of the environment contents. So the letterTwill be put in the margin and the remainder of the text will show up in a normal paragraph.Okay, so to achieve what we want, the
commentenvironment doesn’t need any arguments. What we’ll do is create a box, put the contents of the environment in that box, and then place that box in the margin.Before we get started, if you’re including this code in the preamble of a document, you’ll need to wrap it all in
\makeatletterand\makeatothersince we’ll be using commands with at signs (@) in their names.First, let’s create a box to store the material in:
Next, we’ll start defining the
commentenvironment. We’ll set the environment begin and end commands to\relax. That way our\newenvironmentcommand will be guaranteed to work.With that out of the way, we can define our new
commentenvironment:Now, in your document, you can type:
So just for ease of copying and pasting, here’s what a complete document would look like: