43

I'm looking to write a fictional description/discussion by a 'scholar' of an alien race for an RPG, but I can see this being handy elsewhere.

I'd like to put his 'notes' in the margins of some text he's found/is writing.

I've seen what \marginpar{margin text} can do:

enter image description here

but I'm more after this kind of margin note:

enter image description here

How could I do that with LaTex?

4

1 Answer 1

58

Here is my very unsatisfactory attempt at this, but perhaps someone can use this to come up with a real solution. This just requires way too much tweaking of the paramaters to control the location of the comment text.

enter image description here

References:

Further Enhancements:

  • Replace font of the notes
  • More automatic placement of the comments

Code:

\documentclass{article}
\usepackage{xparse}
\usepackage{tikz}
\usetikzlibrary{calc,fit, decorations.pathmorphing}

\makeatletter
% https://tex.stackexchange.com/questions/39296/simulating-hand-drawn-lines
\pgfdeclaredecoration{penciline}{initial}{
    \state{initial}[width=+\pgfdecoratedinputsegmentremainingdistance,auto corner on length=1mm,]{
        \pgfpathcurveto%
        {% From
            \pgfqpoint{\pgfdecoratedinputsegmentremainingdistance}
                            {\pgfdecorationsegmentamplitude}
        }
        {%  Control 1
        \pgfmathrand
        \pgfpointadd{\pgfqpoint{\pgfdecoratedinputsegmentremainingdistance}{0pt}}
                        {\pgfqpoint{-\pgfdecorationsegmentaspect\pgfdecoratedinputsegmentremainingdistance}%
                                        {\pgfmathresult\pgfdecorationsegmentamplitude}
                        }
        }
        {%TO 
        \pgfpointadd{\pgfpointdecoratedinputsegmentlast}{\pgfpoint{1pt}{1pt}}
        }
    }
    \state{final}{}
}
\makeatother

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}

\newcommand{\CommentText}[3]{\tikzmark{#1}#3\tikzmark{#2}}

\NewDocumentCommand{\CommentPar}{%
    O{}% #1 = draw options for the referenced word
    O{}% #2 = draw options for the comment
    O{}% #3 = draw options for the connecting line
    m  % #4 = left \tikzmark name
    m  % #5 = left \tikzmark name
    m  % #6 = comment
    }{%
    \begin{tikzpicture}[overlay,remember picture,decoration=penciline, thick]
        \node [shape=rectangle,inner sep=0, draw=blue, ,rounded corners=2pt, fit={(#4.south) ($(#5.north)+(0,0.75ex)$)}, decorate, #1] (Source) {};
        \node at ($(#4)!0.5!(#5)$) [blue, font=\itshape, rounded corners=5pt, decorate, #2] (Label) {#6};
        \draw [draw=red, decorate, #3] (Label) to (Source);
    \end{tikzpicture}
}


\begin{document}
Lorem ipsum dolor sit amet, \CommentText{ConsecA}{ConsecB}{consectetur} adipiscing elit. Fusce mollis ullamcorper augue. Cras ut bibendum est. Nullam mauris lectus, imperdiet eget interdum quis, vestibulum quis orci. 
\CommentPar[draw=brown][draw=red, shift={(1.0cm,2.0cm)}, rotate=40, text width=2cm, align=center][out=-110, in=10, distance=0.1cm,->]{ConsecA}{ConsecB}{~~~Did you  \\ mean~~ \\ consecutive??}

\begin{quote}
Ut tellus odio, rhoncus at blandit nec, tempor malesuada nunc. In id euismod odio. Ut lobortis varius pellentesque. Proin molestie \CommentText{estA}{estB}{est} dolor, eu tristique enim. Nulla facilisi. Curabitur pharetra sem eget sem volutpat sed sollicitudin mauris interdum. Nullam iaculis leo vitae tellus mattis aliquam. \CommentText{MexicanA}{MaxicanB}{Maecenas} metus odio, mollis ac posuere vitae, pulvinar ut orci. Nullam porta, dolor vel ornare gravida, leo mauris tempor metus, eu dignissim eros neque quis justo.
\end{quote}

\CommentPar[brown][color=blue, shift={(0.75cm,0.1cm)}, rotate=-50][draw=none]{estA}{estB}{Yes!!}

\CommentPar[brown][text width=3cm, color=violet, shift={(6.7cm,-1.5cm)}, rotate=-65][brown, out=225, in=-80, distance=0.7cm, ->]{MexicanA}{MaxicanB}{Seriously that is how you spell Mexican??}

Nulla massa nisl, tempus sit amet scelerisque ac, vulputate quis ligula. Sed a neque vel enim ultrices ullamcorper. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In hac habitasse platea dictumst. Quisque tincidunt pretium est, vitae ornare urna varius et.  
\end{document}
6
  • 1
    this is great, nice work!
    – cmhughes
    Oct 25, 2012 at 15:10
  • I'd love to try this, but I'm struggling to 'install' xparse.sty ..... Nov 4, 2012 at 12:55
  • 2
    @Pureferret: Can't really help without some information as to what the problem is, error messages, what you tried, etc. i am guessing that you are probably on an older distribution. I'd recommend installing TeXLive 2012 and go from there. If you still have a problem with installation you should ask a new question. Nov 4, 2012 at 18:27
  • @PeterGrill I've go the latest ubuntu. but I'm not sure about tex, I'll give it an update, and if it doesn't work, then yes, I'll ask a new question. Thanks! Nov 4, 2012 at 19:10
  • 1
    @Pureferret: TeXLive 2012 is packaged with Ubuntu 12.10 (the latest at the time of writing), and xparse.sty comes with the texlive-latex-recommended package.
    – krlmlr
    Dec 10, 2012 at 20:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .