- Questo topic ha 10 risposte, 4 partecipanti ed è stato aggiornato l'ultima volta 19 anni, 5 mesi fa da .
-
Topic
-
Beh, mi rendo conto che forse non è il momento migliore (è Ferragosto e il forum sta per chiudere per manutenzione), ma…Sulla Not So Short, viene definito l’ambiente example per riportare codice sorgente LaTeX con a fianco il corrispondente typeset:
`\documentclass[a4paper,11pt]{book}\usepackage{lshort}
\begin{document}
\begin{example}
Il mio numero di telefono presto
cambier\`a. Sar\`a \mbox{0116 291
2319}.Il parametro
\mbox{\emph{nomefile}} deve
contenere il nome del file.
\end{example}\end{document}
`
dove lshort.sty è
`\ProvidesPackage{lshort}\RequirePackage{verbatim}
\RequirePackage{fancyheadings}
\RequirePackage{calc}
\RequirePackage[colorlinks,hyperindex,plainpages=false]{hyperref}% — example —-
% This is an environment to set LaTeX examples.
% On the left side the source text and on the
% right side the typeset text.
%
% \begin{example}
% \Large This is Large
% \end{example}
%
% This Part is stolen from the verbaim.sty by FMi
%
\newwrite\example@out
\newcounter{exacnt}
\setcounter{exacnt}{1}
\newlength{\savefboxrule}
\newlength{\savefboxsep}
\newlength{\outdent}
\setlength{\outdent}{2cm}
\addtolength{\headwidth}{\outdent}
\newenvironment{example}%
{\begingroup% Lets Keep the Changes Local
\@bsphack
\immediate\openout \example@out \jobname.exa
\let\do\@makeother\dospecials\catcode`\^^M\active
\def\verbatim@processline{%
\immediate\write\example@out{\the\verbatim@line}}%
\verbatim@start}%
{\immediate\closeout\example@out\@esphack\endgroup%
%
% And here comes my part. :-
%
\stepcounter{exacnt}%
\setlength{\parindent}{0pt}%
\par\addvspace{3.0ex plus 0.8ex minus 0.5ex}\vskip -\parskip
% Page \lsspageref{exa:\theexacnt}
\expandafter\ifx\csname r@exa:\theexacnt\endcsname\relax\else
\ifx\pdfoutput\undefined % We're not running pdftex
\ifodd\lsspageref{exa:\theexacnt}\hspace*{0pt}\else\hspace*{-\outdent}\fi%
\else
% HyPsd@pageref internal hyperref command v6.69c
\ifodd\HyPsd@pageref{exa:\theexacnt}\hspace*{0pt}\else\hspace*{-\outdent}\fi%
\fi
\fi
\makebox[\textwidth][l]{%
%\raisebox{-\height}[0pt][\totalheight]{%
\begin{minipage}[c]{0.5\outdent+0.46\textwidth-3mm}%
\small\verbatiminput{\jobname.exa}
\end{minipage}%
%}%
\hspace{5mm}%
\setlength{\savefboxrule}{\fboxrule}%
\setlength{\fboxrule}{0.1pt}%
\setlength{\savefboxsep}{\fboxsep}%
\setlength{\fboxsep}{3mm}%
% \raisebox{-\height}[0pt][\totalheight]{%
\fbox{%
\begin{minipage}{0.5\outdent+0.54\textwidth-3.5mm-2\fboxrule-2\fboxsep}%
\setlength{\fboxrule}{\savefboxrule}%
\setlength{\fboxsep}{\savefboxsep}%
\setlength{\fboxrule}{0.5pt}%
\setlength{\parskip}{1ex plus 0.4ex minus 0.2ex}%
\begin{trivlist}\item\small\input{\jobname.exa}
\end{trivlist}
\end{minipage}
}%
% }%
}\label{exa:\theexacnt}%
\par\addvspace{3ex plus 0.8ex minus 0.5ex}\vskip -\parskip
}
`
Ho tolto tutto quello che sono riuscito a togliere. Vorrei eliminare anche fancyheadings e hyperref (ho altri progetti, e i due pacchetti non mi sembrano necessari per lo scopo dell’ambiente considerato), ma se lo faccio ottengo un errore. Come si deve modificare il codice di lshort.sty?Se poi qualcuno di voi ha idee migliori per realizzare lo scopo di example (magari usando lo splendido listings) o anche per evitare che il risultato di example sbordi (a volte succede), è il benvenuto!
Grazie mille,
L.
- Devi essere connesso per rispondere a questo topic.