[comp.text.tex] Re: annotating programs w/ arrows and other text?

Denis Girou Denis.Girou at idris.fr
Fri Aug 7 22:35:56 CEST 1998


-----------------------------------------------------------------------------
This is the PSTricks mailing list, devoted to discussions about computational
graphics in (La)TeX using the PSTricks package from Timothy van Zandt.
For help using this mailing list, see instructions at the end of message.
-----------------------------------------------------------------------------

  As it involve PSTricks, it can interest some of you.

D.G.

Primary message was:

------- Start of forwarded message -------
From: zach at igd.fhg.de (Gabriel Zachmann)
Subject: annotating programs w/ arrows and other text?
Newsgroups: comp.text.tex
Date: 6 Aug 1998 20:31:30 GMT
Organization: Fraunhofer Inst. for Computer Graphics, Darmstadt, Germany
Reply-To: zach at igd.fhg.de
Path: u-psud.fr!jussieu.fr!oleane!news-raspail.gip.net!news-peer.gip.net!news.gsl.net!gip.net!newshub.northeast.verio.net!fu-berlin.de!news.tu-darmstadt.de!zach
Lines: 43
Message-ID: <6qd3r2$gr7$1 at sun27.hrz.tu-darmstadt.de>
NNTP-Posting-Host: rubens.igd.fhg.de
X-realname: Gabriel Zachmann
Mail-Copy-To: zach at igd.fhg.de
X-Newsreader: slrn (0.9.4.3 UNIX)
Xref: u-psud.fr comp.text.tex:10029357


So far, I haven't run into problems which seemed to be unsolvable -
this one is different:

I would like to typeset a piece of text [let's say a piece of a program]
in \texttt [or some other fixed-width font], which has to obey spaces
and tabs. This text goes roughly in the center of the page.
Around this (program) text, I would like to place other little pieces of text
(possibly small paragraphs) with arrows pointing to places in the center text
(explaining something about it).
Probably, I will need to edit later-on the center text as well as the explaining
notes surrounding it. This might involve inserting/deleting several lines.

Well, any idea how I can do this in LaTeX2e?

I know this sounds like a perfect job for a drawing program.
I thought I'd still do this in latex because:
1) it has to be embedded in a latex doc anyway,
2) the layout will be much nicer,
3) the fonts will the same as in the rest of the doc.

I tried using xfig and the psfrag package,
but I ended up editing the .fig files with vi.
What's worse: psfrag doesn't like all the special characters, like { \ } * etc..

I was thinking of pstricks. I haven't tried it, but i'm afraid positiong of
all the little explanatory notes and paragraphs will be PITA.

Any hints, suggestions, etc., will be highly appreciated!
......................................................................
------- End of forwarded message -------

------- Start of forwarded message -------
From: Denis Girou <Denis.Girou at idris.fr>
Newsgroups: comp.text.tex
Subject: Re: annotating programs w/ arrows and other text?
Date: 07 Aug 1998 22:16:35 +0200
Organization: CNRS/IDRIS
Message-ID: <s7r9ysk0nw.fsf at mira.idris.fr>
References: <6qd3r2$gr7$1 at sun27.hrz.tu-darmstadt.de> <s7vho5kctr.fsf at mira.idris.fr> <6qfe1r$9kt$1 at sun27.hrz.tu-darmstadt.de>
Cc: zach at igd.fhg.de (Gabriel Zachmann)

    Gabriel.Zachmann > Thanks a lot for the hint!
    Gabriel.Zachmann > The fancyvrb package is really cool!!
    Gabriel.Zachmann > 
    Gabriel.Zachmann > Still, I've got 2 questions:
    Gabriel.Zachmann > 1) how can i center a fancy-verbatim environment?
    Gabriel.Zachmann >    the BVerbatim env. doesn't seem to work,
    Gabriel.Zachmann >    because I need the commandchars option. Also, enclosing a Verbatim env.
    Gabriel.Zachmann >    inside a center env. doesn't work.
    Gabriel.Zachmann > 2) Positioning the "comments" [e.g., in your example below]
    Gabriel.Zachmann >    to somewhere to the left and right of the verbatim text could become
    Gabriel.Zachmann >    difficult, couldn't it?
    Gabriel.Zachmann >    How would you do that?

  1) As you understand, you must use the BVerbatim environment to be able to
center the verbatim text with the center environment. BVerbatim, as the B show
it, use a box (it is also how the `verbatim' package proceed with the
\verbatimboxed macro which center the verbatim text). Nevertheless, BVerbatim
doesn't support all the `fancyvrb' functionnalities, so it is not a solution
for all cases. But, as the opposite you believe, the commandchars parameter is
active. So, it can be enough in your case.

     If not, the alternative is to use the xleftmargin and xrightmargin
parameters with the Verbatim environment. It require little manipulation, but
it is easy. Just don't forget to compute the length using the text in the font
which will be used in the Verbatim environment - \texttt by default.
(If you have not and do not want to install the last version of the `calc'
package, which add convenient macros like \widthof, proceed in the standard
way.)

     I'll add such example in the `fancyvrb' documentation...

\documentclass{article}

\usepackage{fancyvrb}
\usepackage{calc} % Must be >= 1998/07/07 v4.1b which add \widthof, etc. macros

\pagestyle{empty}

\setlength{\parindent}{0cm}

\begin{document}

\rule{\textwidth}{1mm}
\begin{center}
\begin{BVerbatim}[commandchars=\\\{\}]
\emph{First line}
Second
\end{BVerbatim}
\end{center}

\rule{\textwidth}{1mm}
\begin{center}
\begin{BVerbatim}[frame=single,numbers=left,commandchars=\\\{\}]
\emph{First line}
Second
\end{BVerbatim}
\end{center}

\rule{\textwidth}{1mm}
\begin{Verbatim}[xleftmargin=0.3\textwidth]
Verbatim line.
\end{Verbatim}

\fvset{frame=single,numbers=left,numbersep=3pt}

\rule{\textwidth}{1mm}
\begin{Verbatim}[xleftmargin=0.3\textwidth]
Verbatim line.
\end{Verbatim}

\rule{\textwidth}{1mm}
\begin{Verbatim}[xleftmargin=0.3\textwidth,xrightmargin=0.3\textwidth]
Verbatim line.
\end{Verbatim}

\newlength{\Margin}
\setlength{\Margin}{%
(\textwidth - \widthof{\texttt{Longest verbatim line.}} - \fboxsep - \fboxsep)%
/ \real{2}}

\rule{\textwidth}{1mm}
\begin{Verbatim}[xleftmargin=\Margin,xrightmargin=\Margin]
First line.
Second line.
Longest verbatim line.
Fourth line.
\end{Verbatim}

\end{document}

  2) One time more, it is not too difficult if you use a box (BVerbatim
environment for instance - here I use the SaveVerbatim one with \BUseVerbatim
to be able to put a frame around the box). If you don't use a box but the
Verbatim environment, it is possible too and not so difficult, but with little 
more work...

\documentclass{article}

\usepackage{fancyvrb}
\usepackage{pst-node}
\usepackage{calc} % Must be >= 1998/07/07 v4.1b which add \widthof, etc. macros

\newlength{\Margin}
\newlength{\TextLength}
\newlength{\MyLength}

\setlength{\parindent}{0cm}

\pagestyle{empty}

\begin{document}

\setlength{\TextLength}{\widthof{\texttt{Longest verbatim line.}}}

\setlength{\Margin}{(\textwidth - \TextLength - \fboxsep - \fboxsep) / \real{2}}

\fvset{numbers=left,numbersep=3pt,frame=single,commandchars=\\\{\}}

\psset{arrows=->,arrowscale=2,border=2pt,nodesep=1pt}

% Solution with a box: BVerbatim environment or SaveVerbatim one + \BUseVerbatim

\begin{SaveVerbatim}{VerbEnv}
\pnode{NodeXB}First line.
Second line.
\rnode{NodeYB}{Longest verbatim} line.
Fourth line.
\end{SaveVerbatim}

\begin{minipage}{2cm}
  Comments\\
  on line 1.%
  \pnode(0,0.5\baselineskip){NodeXA}
\end{minipage}
\hfill
%
\fbox{%
\begin{minipage}{\TextLength}
  \BUseVerbatim{VerbEnv}
\end{minipage}}
\hfill
%
\begin{minipage}{2cm}
  Comments\\
  \pnode(0,0.5\baselineskip){NodeYA}%
  on line 3.
\end{minipage}

% Connections
\ncline{NodeXA}{NodeXB}
\ncarc[arcangle=20]{NodeYA}{NodeYB}

% Solution with Verbatim environment

\begin{Verbatim}[xleftmargin=\Margin,xrightmargin=\Margin]
\pnode{NodeXB}First line.
Second line.
\rnode{NodeYB}{Longest verbatim} line.
Fourth line.
\end{Verbatim}

\rput(1,4\baselineskip){%
\begin{minipage}{2cm}
  Comments\\
  on line 1.%
  \pnode(0,0.5\baselineskip){NodeXA}
\end{minipage}}
%
\setlength{\MyLength}{\textwidth - 1cm}
\rput(\MyLength,4\baselineskip){%
\begin{minipage}{2cm}
  Comments\\
  \pnode(0,0.5\baselineskip){NodeYA}%
  on line 3.
\end{minipage}}

% Connections
\ncline{NodeXA}{NodeXB}
\ncarc[arcangle=20]{NodeYA}{NodeYB}

\end{document}

Denis Girou
--
---------------------------------------------------------------------------
Institut du De'veloppement et des Ressources en Informatique Scientifique |
Centre National de la Recherche Scientifique                              |
Ba^timent 506 - B.P. 167 - 91403 Orsay Cedex - France                     |
---------------------------------------------------------------------------
------- End of forwarded message -------

-----------------------------------------------------------------------------
The list interface (subscription, information, access to the archives) is on:
http://www.tug.org/cgi-bin/lwgate/pstricks
Otherway to unsubscribe, send mail to pstricks-request at mail.tug.org
with a blank subject and in body the line unsubscribe <email-address>
-----------------------------------------------------------------------------



More information about the PSTricks mailing list