\raggedouter to typeset marginal text in twoside book

The command \marginpar already does the check for odd pages or even pages, so it's simpler to say

\newcommand{\mymarginpar}[1]{%
  \marginpar[\raggedleft#1]{\raggedright#1}}

and to use \mymarginpar to insert marginal notes. Of course you can change \raggedright and \raggedleft with the similar commands provided by ragged2e, if you think they are better for you.

You may want to load also mparhack, probably.


Have you looked at the raggedrightboxes option of the ragged2e package? It almost achieves what you're looking for. :-) Unfortunately, there's no raggedboxes option, but that's easily fixed, as the remainder of this example explains.

Create a copy of the ragged2e.sty (which should be located under TEXHOME/texmf-dist/tex/latex/ms/) and name the new file (say) newragged2e.sty. The relevant lines of the package file are 84 to 115 (at least in my copy of the package). First, copy and paste this range of lines verbatim to immediately after this range. Next, change the first line,

\newcommand*{\@raggedtwoe@raggedrightboxes@opt}{

to

\newcommand*{\@raggedtwoe@raggedboxes@opt}{

and change the last line,

\DeclareOption{raggedrightboxes}{\@raggedtwoe@raggedrightboxes@opt}

to

\DeclareOption{raggedboxes}{\@raggedtwoe@raggedboxes@opt}

Third, replace the instruction

  \RaggedRight

located towards the end of the \@arrayparboxrestore command with

  \raggedouter

where \raggedouter is defined in your code example. (Note for readers other than the OP: the command \checkoddpage that is used in the definition of the raggedouter command is provided by the changepage package.) Run texhash (if needed) to make your TeX system aware of the new package myragged2e. Finally, load the myragged2e package with the raggedboxes option set, and you should be in business. :-)