1

Is it possible to make annotations to source codes like below?

enter image description here

  • 2
    Welcome to TeX.SE! Please show us the tex code you have so far! – Mensch Jun 9 at 19:48
1

You want two things: (1) add footnotes to the listing, and (2) change the way footnotes look. Lets us do both.

The package fancyvrb allows to add arbitrary TeX commands to a verbatim text. So

\begin{Verbatim}[\commandchars=\\\{\}]
  text\footnote{this is a footnote}
\end{Verbatim}

will add a footnote to the verbatim snippet. Since we want the footnotes to be close to the listing, let us put the snippet in the minipage, then footnotes automatically become minipage footnotes. Now, you want footnote mark to be a dingbat, and to typeset footnote marks flush right. The first is achieved by

\makeatletter
\renewcommand{\thempfootnote}{\ding{\numexpr(181+\c@mpfootnote)}}
\makeatother

the second by defining a special command

\newcommand{\commentcode}[1]{\hfill\footnote{#1}}

All together:

\documentclass{article}
\usepackage{fancyvrb}
\usepackage{pifont}
\makeatletter
\renewcommand{\thempfootnote}{\ding{\numexpr(181+\c@mpfootnote)}}
\makeatother
\newcommand{\commentcode}[1]{\hfill\footnote{#1}}
\begin{document}
\thispagestyle{empty}
\begin{minipage}{\textwidth}
\begin{Verbatim}[commandchars=\\\{\}]
wget ftp://ftp.gnu.org/gsl/gsl-1.16.tar.gz\commentcode{Download the zipped archive}
tar xzvf \commentcode{Unzip the archive}
cd gsl-1.16
./configure
make
sudo make install
\end{Verbatim}
\end{minipage}
\end{document}

Result:

enter image description here

  • Thanks @Boris. This is it. I have one more question is it possible to add hyperlink from listing line to footnote and from footnote to the line of listing? – k3be Jun 10 at 6:49
  • \usepackage{hyperref} will give you links from the code to comments – Boris Jun 10 at 14:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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