# ConTeXt: Margin notes ragged right in both margins

I'm struggling with margin notes in ConTeXt. Here I have a MWE of what I could achieve, with the invaluable help of many people in StackExchange. Now, I want all margin notes (those in left as in right margin) ragged right. I've tried to find a way in ConTeXt Reference Manual, 2013 version but in 4.7 it says: "Text in the margin. FIXME. The syntax of the margin commands has changed in mark IV". Nonetheless, I've tried to get the right ragged text I want with this, buy I couldn't do that. Next, I looked in the web but I found nothing clear to me. Could someone obtain ragged right text in both margins over the MWE? Thanks!

\mainlanguage[es]
\language[es]
\usecolors[xwi]
\definecolor[marca][h=e80000]

\newdimen\Margin
\Margin=3.5cm
\newdimen\MarginRaise
\MarginRaise=56ex

\setuppagenumbering
[alternative=doublesided, location=]

\setupinterlinespace[small]

\setupmargindata[location=both, align=left,stack=yes, stack=continue, style=\tfx\setupinterlinespace]

\newcounter\MyMarginalNote
\def\mnote{\dosingleempty\domnote}

\def\domnote[#1]#2%
{\doglobal\increment\MyMarginalNote
\high{{\tfxx\color[marca]{\MyMarginalNote}}}%
\inouter
{{\tfx\color[marca]{\MyMarginalNote:}}
\doifsomething{#1}
{\expanded{\textreference[#1]{\MyMarginalNote}}}\tfx\it {#2}}}

\starttext
\input ward\mnote{\input {knuth}}
\input bryson
\input dawkins
\input douglas
\input reich\mnote{\input{zapf}}
\input reich
\input zapf

\stoptext


There are two types of margin mechanisms in MkIV: margindata and marginframed. In margindata the margin text is simply set in a \vbox; in marginframed the margin text is set in \framed (technically, a lower level command than framed, but it helps to think of it as a framed). For most cases, margindata is sufficient; marginframed is useful when you want to use some of the framed parameters (offset, frame, etc.) to change the visual appearance.

The following macros are defined as margindata:

• \inleftmargin, \inrightmargin, inoutermargin, \ininnermargin
• \inleftedge, \inrightedge, \inoutedge, \ininneredge
• \atleftmargin, \atrightmargin.

The following are defined as marginframed:

• \inleft, \inright, \inouter, \ininner, \inmargin, \inother.

Now, where things get a little confusing is that for marginframed some of the parameters are set using \setupmargin while some are set using \setupmarginframed. align is one of the parameters that is set using \setupmarginframed. (It is possible that the align for \setupmarginframed gets inherited from \setupmargindata; I consider the current behavior a misconfiguration).

So, in your example, you should either

1. Use \inoutermargin (the margindata variant) instead of \inouter
2. Use \setupmarginframed[inouter][align=flushleft].

I show the complete example with the second alternative below. I also cleaned up some of the other code (using measures and ConTeXt counters; the advantage of ConTeXt counters is that you have easily change the conversion if you wish)

\mainlanguage[es]

\definecolor[marca][h=e80000]

\definemeasure[Margin][3.5cm]

\setuppagenumbering[alternative=doublesided, location=]

\setuplayout
[
backspace=20mm,
width=120mm,
height=middle,
footer=\bodyfontsize,
bottom=3\bodyfontsize,
location={middle},
margin=\measure{Margin},
rightmargin=4.5cm,
marking=on,
]

\setupinterlinespace[small]

\setupmargindata[stack=continue, style=\tfx\setupinterlinespace]
\setupmarginframed[inouter] [align=flushleft]

\definecounter[MyMarginNote][numberconversion=numbers]

\def\mnote{\dosingleempty\domnote}

\def\domnote[#1]#2%
{\incrementcounter[MyMarginNote]%
\high{{\tfxx\color[marca]{\convertedcounter[MyMarginNote]}}}%
\inouter
{{\tfx\color[marca]{\convertedcounter[MyMarginNote]:}}%
\doifsomething{#1}
{\expanded{\textreference[#1]{\convertedcounter[MyMarginNote]}}}\space
\tfx\it {#2}}}

\starttext
\input ward\mnote{\input {knuth}}
\input bryson
\input dawkins
\input douglas
\input reich\mnote{\input{zapf}}
\input reich
\input zapf
\stoptext

• Excellent! Thank you very much! Did you learn that studying the code (or producing it, you have such expertise in ConTeXt that i think it's possible you are developing the system) or in some documentation? – Miguel Aug 29 '16 at 10:28
• @Miguel: I had never used margin notes in the past and read the source to understand what was happening. I am not one of the developers of ConTeXt; just a user. – Aditya Aug 29 '16 at 17:28
• Wow! I'd like to be able of do that! But it's impossible with my knowledge and skills. Thank you very much for your time and work! – Miguel Aug 29 '16 at 18:26