1

I am trying to write a simple macro that will add a sidenote which will inline the note if it is added to a caption. To do this I am testing if I am in inner mode, but the test doesn't seem to work. Can anyone suggest what I should do? Here is an example of the failing code. The key is my definition of \addnote on line 9 which should either add a sidenote or just add in the text.

\documentclass[12pt]{article}

\usepackage{sidenotes}
\usepackage{setspace}
\usepackage{color}


\def\mysidenote#1#2{\color{#1}\marginpar{\footnotesize\setstretch{0.9}\raggedright\color{#1} #2}}
\def\addnote#1#2{\ifinner{\color{#1} #2}\else \mysidenote{#1}{#2} \fi}
%\def\addnote#1#2{\mysidenote{#1}{#2}}

\usepackage[total={6.5in,8.5in},top=1in,left=.75in,marginparwidth=2.5in,, marginparsep=.1in,includeall]{geometry}
\begin{document}
here is some text\addnote{red}{the first note} and some more text\addnote{blue}{the second note} and blah blah.
\begin{figure}
a figure
\caption{figure caption\addnote{green}{note in caption}}
\end{figure}
and some more text after the figure.
\end{document}

When the above code is run through pdflatex, I get:

! LaTeX Error: Float(s) lost.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.20 \end{document}

Note, that if I don't put the \ifinner test in the definition of \addnote, then instead I get:

! LaTeX Error: Not in outer par mode.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.17 ...e caption\addnote{green}{note in caption}}

So, the test is doing something, just not what I want it to do. Any suggestions would be welcome.

0

The test from here seems to work.

\documentclass[12pt]{article}

\usepackage{sidenotes}
\usepackage{setspace}
\usepackage{xcolor}
\makeatletter   
\newcommand\ifInFloat[2]{\@ifundefined{@captype}{#2}{#1}}
\makeatother

\def\mysidenote#1#2{\color{#1}\marginpar{\footnotesize\setstretch{0.9}\raggedright\color{#1} #2}}
\def\addnote#1#2{\ifInFloat{\color{#1} #2}{\mysidenote{#1}{#2}}}

\usepackage[total={6.5in,8.5in},top=1in,left=.75in,marginparwidth=2.5in,, marginparsep=.1in,includeall]{geometry}
\begin{document}
here is some text\addnote{red}{the first note} and some more text\addnote{blue}{the second note} and blah blah.
\begin{figure}
a figure
\caption{figure caption 
\protect\addnote{green}{note in caption}
}
\end{figure}
and some more text after the figure. 
\end{document}

enter image description here

| improve this answer | |
  • Awesome, thanks! – seth Jun 3 at 13:52

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.