3

I defined this function \corr which marks a segment of text or equation in red or blue and adds a marginnote. The problem is having more than one correction per line since then hey overlap. I would like to display them side by side if there is more than one per line. Here is my code:

\documentclass[]{article}
\usepackage{xstring}
\usepackage{marginnote}
\usepackage{tikz}

\newcounter{correctioncounter}

\newcommand{\corr}[2]{%
    \refstepcounter{correctioncounter}%
    \IfEqCase{#1}{
        {a}{{\color{red}#2\marginnote{%
                    \begin{tikzpicture}%
                    \draw node[draw,inner sep=2pt] {\tiny \arabic{correctioncounter}};
                    \end{tikzpicture} }}}% correction
        {b}{{\color{blue}#2\marginnote{%
                    \begin{tikzpicture}%
                    \draw node[draw,inner sep=2pt] {\tiny \arabic{correctioncounter}};
                    \end{tikzpicture} }}}% suggestion
        {c}{#2}% Turn correction into plain text
        {d}{} % Erase
    }[\PackageError{correction command}{Undefined for corr: #1}{}]%
}
\begin{document}

Random text with a \corr{a}{correction} in one line.

Having more than one \corr{a}{correction} in \corr{a}{one} line causes them to overlap. Some more random text to show that the annotations are really in the \corr{b}{margin}. 

\end{document}

And the output: enter image description here

2

You can add another argument for \corr which control \marginparsep and reset it's default value. If the marginnote is not the last in current line you must add add to corr command like this \corr[add]{a}{text}

\documentclass[]{article}
\usepackage{xstring}
\usepackage{marginnote}
\usepackage{tikz}

\newcounter{correctioncounter}

\newcommand{\corr}[3][]{%
    \refstepcounter{correctioncounter}%
    \IfEqCase{#2}{
        {a}{{\color{red}#3\marginnote{%
                    \begin{tikzpicture}%
                    \draw node[draw,inner sep=2pt] {\tiny \arabic{correctioncounter}};
                    \end{tikzpicture}}}}% correction
        {b}{{\color{blue}#3\marginnote{%
                    \begin{tikzpicture}%
                    \draw node[draw,inner sep=2pt] {\tiny \arabic{correctioncounter}};
                    \end{tikzpicture} }}}% suggestion
        {c}{#3}% Turn correction into plain text
        {d}{} % Erase
    }[\PackageError{correction command}{Undefined for corr: #2}{}]
    \IfEqCase{#1}{{add}{\advance \marginparsep by 3mm}{}{\marginparsep=11pt}}
}
\begin{document}

Random text with a \corr{a}{correction}\ in one line.

Having more than one \corr[add]{a}{correction}\ in \corr[add]{a}{one}\ line causes them to  \corr{b}{overlap}. Some more random text to show that the annotations are really in the \corr{b}{margin}. 

\end{document}

enter image description here

1
  • Amazing! I know this is maybe asking for too much, but do you think it would be possible to automate it? Im asking because if you add something above the corrections it may move them so they end up in different lines.
    – Josh
    Sep 30 '16 at 8:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.