Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color of margin notes not properly set #13

Open
aoles opened this issue Jun 30, 2016 · 1 comment
Open

Color of margin notes not properly set #13

aoles opened this issue Jun 30, 2016 · 1 comment

Comments

@aoles
Copy link

aoles commented Jun 30, 2016

Hi Stephen,
first of all, many thanks for your great package! It's superior to any other solution for positioning margin notes.

I've noticed the following problem: when marginfix is used, margin notes render with the color which was active at the beginning of the page. This is different from the way regular \marginpar works, and may lead to some unexpected behavior. Consider the following example of three paragraphs, each typeset with a different color and each containing a margin note.

\documentclass{article}

\usepackage{blindtext}
\usepackage{color}
\usepackage{marginfix}

\begin{document}

\color{blue}
\blindtext
\marginpar{Blue Note}
\blindtext

\color{red}
\blindtext
\marginpar{Red Note}
\blindtext

\clearpage

\color{green}
\blindtext
\marginpar{Green Note}
\blindtext

\end{document}

marginfix

As illustrated above, the colors of margin notes don't match the paragraph colors. Instead, the notes display in a color which is "carried over" from a previous context. I believe in most cases this is not the desired behavior. Rather, one would expect the notes to use the color which was active when they were defined. When I comment out \usepackage{marginfix}, the margin notes have the same color as the color of the paragraph in which they appear.

Any thoughts on how this issue could be resolved? Any help is highly appreciated!

Thanks,
Andrzej

@aoles aoles changed the title Color of margin notes is not set properly Color of margin notes not properly set Jun 30, 2016
@aoles
Copy link
Author

aoles commented Jul 1, 2016

I was able to circumvent this issue by patching the internal LaTeX macro \@savemarbox to save the current color that is active when the box is build. This is achieved by enclosing the #2 argument in \color@setgroup and \color@endgroup, as illustrated below.

\documentclass{article}

\usepackage{blindtext}
\usepackage{color}
\usepackage{marginfix}

\makeatletter
\long\def \@savemarbox #1#2{%
  \global\setbox #1%
    \color@vbox
      \vtop{%
        \hsize\marginparwidth
        \@parboxrestore
        \@marginparreset
        \color@setgroup#2\color@endgroup% save the currently active color
        \@minipagefalse
        \outer@nobreak
        }%
    \color@endbox
}
\makeatother

\begin{document}

\color{blue}
\blindtext
\marginpar{Blue Note}
\blindtext

\color{red}
\blindtext
\marginpar{Red Note}
\blindtext

\clearpage

\color{green}
\blindtext
\marginpar{Green Note}
\blindtext

\end{document}

mirginfix

Do you think this patch could make it's way into marginfix?

Cheers,
Andrzej

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant