0

The following code will be referred multiple times in my questions later. Patching is needed to make the frames of both source code and formatted text inside the text width.

\documentclass{article}
\usepackage[showframe=false,a5paper,margin=1cm]{geometry}

\usepackage{showexpl,xcolor,caption}
\captionsetup
{
        margin=5mm,
        font={color=blue,rm,scriptsize},
        labelfont={color=magenta,bf},
        justification=justified,
        labelsep=quad
}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\SX@codeInput}{xleftmargin=0pt,xrightmargin=0pt}{}
  {\typeout{***Successfully patched \protect\SX@codeInput***}}
  {\typeout{***ERROR! Failed to patch \protect\SX@codeInput***}}
\makeatother

\lstset
{
    language={[LaTeX]TeX},   
    breaklines=true,
    basicstyle=\scriptsize\ttfamily,
    keywordstyle=\color{blue}\sffamily\bfseries,                                   
    backgroundcolor=\color{yellow!10},
    frame=single,
    rulecolor=\color{red},
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % the following must be defined to make hacking work.
    xleftmargin=\dimexpr\fboxsep+\fboxrule\relax, 
    xrightmargin=\dimexpr\fboxsep+\fboxrule\relax,
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    vsep=2\fboxsep,
    explpreset={}%must be called even if empty
}

\newcommand\dummy
{%
    Anger is a condition in which the tongue works faster than the mind \ldots
}

\parindent=0pt

\begin{document}
\dummy
\begin{LTXexample}[caption=\dummy]
\dummy
\[E\not=mc^2\]
\end{LTXexample}
\dummy
\end{document}

Question

The other 3 questions have been removed and the following one is left to support the answer provided by Herbert. Use edit history button to see the original.

In side-by-side mode (either pos=l or pos=r), how to align the top frames with the same horizontal line?

Herbert's answer plus aboveskip=\dimexpr\fboxsep+\fboxrule\relax will answer this question.

Display Name
  • 46,933
  • Patching only works when frame=single and pos=b/t. When frame=single and pos=l, the patch does not work because the source code's right edge goes beyond the text width as shown above. – Display Name Aug 07 '11 at 18:32

1 Answers1

1

it makes no sense to patch the command as you did. However, getting both on top aligned, insert in the preamble:

\makeatletter
    
\renewcommand\SX@ResultArea[2]{%
      
  \SX@justification\setlength\@tempdima{#1}%
      
  \parbox[t]\@tempdima{\vspace{0pt}#2}}
    
\renewcommand\SX@CodeArea[2]{%
      
  \setlength\@tempdima{#1}%
      
  \sbox\@tempboxa{\parbox[t]\@tempdima{\vspace{0pt}#2}}%
      
  \@tempdima=\dp\@tempboxa\usebox\@tempboxa
      
  \rlap{\raisebox{-\@tempdima}[0pt][0pt]{\SX@attachfile}}}
    
\makeatother