Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

closed as too localized by Lev Bishop, Seamus, Joseph Wright Aug 11 '11 at 16:36

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
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. –  xport Aug 7 '11 at 18:32

1 Answer 1

up vote 1 down vote accepted

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
    
share|improve this answer
    
+1 The patch is necessary when pos=b or pos=t. –  xport Aug 7 '11 at 11:20
    
xleftmargin and xrightmargin are set by explpreset=... and are parameters of listings and no normal length registers –  Herbert Aug 7 '11 at 11:29
    
I need to use aboveskip=\dimexpr\fboxsep+\fboxrule\relax and your code above to align the top frames. –  xport Aug 7 '11 at 11:54
    
Redefining xleftimargin and xrightmargin in explpreset will not help if pos=t/b and frame=single are used. Thus patching is really needed. –  xport Aug 7 '11 at 18:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.