# how to use \marginnote in mdframed environment? (follow up)

I need to have a line on the INNER margin in a double-sided tufte-document. There was a close question and it has this answer. That answer is perfect. Their output is: (You see the line on the INNER part of the page)

The difference is that I use tufte-book class, but that example is for an article class. As soon as I use \marginnote{Hello} in this code snippet LaTex gives a mistake ! LaTeX Error: Not in outer par mode.

\begin{mdframed}[style=MDFStyGrayBar]
\lipsum
%\marginnote{Hello}
\lipsum
\end{mdframed}


(for the full code shamelessly stolen from the link, see below)

I wonder how to use \marginnote in mdframed environment, if possible. My search led to this question, that also doesn't have any answer.

I also have quite a number of \marginnote, marginfigure and figure* floats (with some tikz stuffing). I assume they all work the same, so I hope they will work as soon as the problem will be solved for at least one of them.

Any code modifications are welcome, as I still don't understand how that solution works anyway (I am freaking out as I see @ and code around it).

\documentclass[twoside,symmetric,notoc,justified]{tufte-book}%

\usepackage[utf8]{inputenc}
\usepackage[latin]{babel}
\usepackage[OT1]{fontenc}
\usepackage[pdftex]{graphicx}
\usepackage{lipsum}
\usepackage{float}
\usepackage{pgf,caption,calc}
\usepackage{tikz,tkz-euclide}
\usetkzobj{all}

\geometry{
%showframe,
paperwidth=145mm,
paperheight=215mm,
inner=16mm,
outer=10mm,
top=10mm,
bottom=40mm,
marginparsep=3mm,
marginparwidth=40mm,
includemp,
}
\usepackage[framemethod=TikZ]{mdframed}
\makeatletter
\newrobustcmd*\if@mdf@pageodd@bar{%
\zref@refused{mdf@pagelabel-\the\value{mdf@zref@counter}}%
\ifodd\zref@extract{mdf@pagelabel-\the\value{mdf@zref@counter}}%
{mdf@pagevalue}%
\setlength\mdf@rightmargin@length{\mdf@outermargin@length}%
\setlength\mdf@leftmargin@length{\mdf@innermargin@length}%
\mdfsetup{hidealllines=true,leftline=true}%
\else
\setlength\mdf@rightmargin@length{\mdf@innermargin@length}%
\setlength\mdf@leftmargin@length{\mdf@outermargin@length}%
\mdfsetup{hidealllines=true,rightline=true}%
\fi%
}
\newrobustcmd*\changepageodd{\let\if@mdf@pageodd\if@mdf@pageodd@bar}
\makeatother
\mdfdefinestyle{MDFStyGrayBar}{%
linecolor=gray,
backgroundcolor=white,
%
outerlinewidth=5pt,
%
topline=false,
bottomline=false,
rightline=false,
leftline=true,
%
innertopmargin=4pt, %\baselineskip
innerbottommargin=8pt,
innerrightmargin=3pt,
innerleftmargin=3pt,
%
skipabove=\topskip,
skipbelow=\topskip,
settings={\changepageodd}
}
\usepackage{showframe,lipsum}
\begin{document}

\noindent Some normal text.
\begin{mdframed}[style=MDFStyGrayBar]
\lipsum
%\marginnote{Hello}
\lipsum
\end{mdframed}

\end{document}

• Generally you cannot, \marginnote is a float and it cannot escape the mdframed boxes. I don;t quite understand what you are mentioning about a line, please update your question to something that are clearer to understand. Also don't put your questions into the bounty. – daleif Jan 29 '18 at 13:25
• @dalief, sorry, I was not sure. Then the hint -box asked me for the clarification for the answerer, I did my best. Should I update my question by adding possible ways to resolve it (or at least the ways that would work or me)? – Sergey Belyaev Jan 29 '18 at 13:48
• You should at least update your question so it is clearer what you are asking. Note that the site favours clear explicit questions, not "please do this for me" questions. – daleif Jan 29 '18 at 14:37

The \marginnote definition of the tufte-book class is based on \marginpar. This is a float and it won't work inside a mdframed environment.

You can switch to the \marginnote definition of the marginnote package, which is not a float. Be aware that this completly overwrite the tufte-definition. So none of the tufte settings or options will apply:

\documentclass[twoside,symmetric,notoc,justified]{tufte-book}%
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage[framemethod=TikZ]{mdframed}

\let\marginnote\someundefinedcommand
\usepackage{marginnote}

\begin{document}

\noindent Some normal text.
\begin{mdframed}
blblb
\marginnote{Hello}
\end{mdframed}

\end{document}


• Thank you. I accept it as the answer. Unfortunately, this solution does not allow to place figures and TikZ pictures in the '\marginpar' environment redefined like that. I have a lot of stuff like that. It looks like I have to find another way to emphasize several paragraphs. This solution brings me more problems than this particular one resolved. – Sergey Belyaev Jan 30 '18 at 14:05
• It should be no problem to add a tikz picture inside a \marginnote. And you can add figures, if you don't use the figure environment. – Ulrike Fischer Jan 30 '18 at 14:07