Folks,

The memoir class manual suggests some code for putting section
headings in the margin, which I have adapted (using Expl3 mode for
clarity) thus:

    \newcommand{\marginbox}[1]
      {
        \parbox[t][0pt]
          { \c_jcsres_marginwidth_dim }
          { \raggedleft \leavevmode \jcsres_section_style:n {#1} }
      }
    \newcommand{\marginhead}[1]
      {
        { \llap { \marginbox{#1} \kern \c_jcsres_marginspace_dim } }
      }
    \setbeforesecskip{ \c_jcsres_section_dim }
    \setsecindent{ 0em }
    \setaftersecskip{ 0em }
    \setsecheadstyle{ \marginhead }
    \setsecnumformat{}

I’m trying to customize this code and I keep getting stuck in not
understanding quite what’s going on. I’m hoping that translating the
`\marginhead` and `\marginbox` functions to use Expl3 features will
make matters explicit enough that I can tweak matters on my own.

If I understand correctly, `\marginbox` creates a 0-height top-aligned
box, the width of the margin (that’s the same dim variable I used in
creating the page layout) with the correctly-styled heading text set
ragged-left; and `\marginhead` places this box the appropirate
distance to the left of the following body text.

What is the cleanest way to do this with Expl3? Specifically, what are
the Expl3 equivalents of `\parbox` and `\llap`, at least in the way
this code uses them?

(I understand that `\raggedleft` would be in a very different layer of
the code [the galley?] and probably doesn’t have a useable Expl3
equivalent yet; and that using `\tex_kern:D` is no clearer than
`\kern`, and that its Expl3ization will probably be in the fonts
module. On the other hand, I see that l3trial/xfont/xfss.dtx includes
a definition for `\mode_leave_vertical:` so perhaps I’ll copy its
definition and use that.)

—Joel C. Salomon