Document ClassesWarning when "showexpl" used in conjuction with "hyperref"

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
fractal.generator
Posts: 66
Joined: Tue Oct 07, 2008 9:39 am

Warning when "showexpl" used in conjuction with "hyperref"

Post by fractal.generator »

Dear all,

I used showexpl package in junction with hyperref package.

When I use two consecutive \LTXinputExample commands with captions, I get many warning as follows
warning wrote:! pdfTeX warning (ext4): destination with the same
identifier (name{page.1}) has been already used,
duplicate ignored
Here is my trivial minimal input file:

Code: Select all

 \documentclass{book}

\usepackage{showexpl}
\lstset{explpreset={pos=b}}

\usepackage[a4paper, margin=2cm]{geometry}
\usepackage{hyperref}

\begin{document}

\LTXinputExample[caption={data1}]{data1.tex}
\LTXinputExample[caption={data2}]{data2.tex}

\end{document}

The content of data1.tex :

Code: Select all

111111111 
111111111 
111111111 
111111111 
111111111 
111111111 
111111111 
111111111 
111111111 
111111111 
111111111 
111111111 
111111111 
111111111 
111111111 
111111111 
111111111 
111111111 
111111111 
111111111 
111111111
The content of data2.tex :

Code: Select all

222222222 
222222222 
222222222 
222222222 
222222222 
222222222 
222222222 
222222222 
222222222 
222222222 
222222222 
222222222 
222222222 
222222222 
222222222 
222222222 
222222222 
222222222 
222222222 
222222222 
222222222
The warning appears when there are at least two consecutive \LTXinputExample commands with captions.

The warning will disappear when I either
remove the caption from \LTXinputExample
or remove the hyperref package from the preamble.

What should I do to remove the warning?


Regards,


Hayashi
Last edited by fractal.generator on Thu Oct 16, 2008 12:48 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

fractal.generator
Posts: 66
Joined: Tue Oct 07, 2008 9:39 am

Warning when "showexpl" used in conjuction with "hyperref"

Post by fractal.generator »

I got the source of problem but I have NOT found the solution.

The warning will disappear when all "caption" keys are removed from the \LTXinputExample.

Anybody can figure out this mistery?


Hayashi
Last edited by fractal.generator on Thu Oct 16, 2008 12:52 pm, edited 1 time in total.
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Warning when "showexpl" used in conjuction with "hyperref"

Post by Juanjo »

I've seen your different posts about code inclusion. I think you've missunderstood the use of the showexpl pakage. It is intended to present LaTeX code and, at the same time, the corresponding output. For C# code, you should directly use listings. I presume that you like the layout provided by showexpl. To obtain it, you can simply copy the contents of showexpl.cfg and adapt it. I've done that. Look at the following example:

Code: Select all

\begin{filecontents*}{program.cs}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}
\end{filecontents*}

\documentclass{book}

\usepackage[a4paper, margin=2cm]{geometry}
\usepackage{listings}
\usepackage{xcolor}

% --- Taken from showexpl.cfg and slightly modified ---
\definecolor{hellgelb}{rgb}{1,1,0.85}
\definecolor{colKeys}{rgb}{0,0,1}
\definecolor{colIdentifier}{rgb}{0,0,0}
\definecolor{colComments}{rgb}{1,0,0}
\definecolor{colString}{rgb}{0,0.5,0}

\lstset{%
     language=[Sharp]C,%
     float=hbp,%
     basicstyle=\footnotesize\ttfamily,%
     identifierstyle=\color{colIdentifier},%
     keywordstyle=\color{colKeys},%
     stringstyle=\color{colString},%
     commentstyle=\itshape\color{colComments},%
     columns=fixed,
     tabsize=4,%
     frame=single,%
     framerule=1pt,
     extendedchars=true,%
     showspaces=false,%
     showstringspaces=false,%
     numbers=left,%
     numberstyle=\tiny\ttfamily,%
     numbersep=1em,%
     breaklines=true,%
     breakindent=10pt,%
     backgroundcolor=\color{hellgelb},%
     breakautoindent=true,%
     captionpos=t,%
     xleftmargin=1em,%
     xrightmargin=\fboxsep,%
     numbersep=1em%
}
% ------------------------------------------------

\usepackage{hyperref}

\begin{document}
\lstinputlisting[caption={First example}]{program.cs}
\lstinputlisting[caption={Second example}]{program.cs}
\end{document}
The above code compiles perfectly in my computer, without the annoying hyperref warnings you have reported. The filecontents environment just write the file program.cs you gave before editing your posts. Once generated the file (after one LaTeX run), you can remove that environment.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
fractal.generator
Posts: 66
Joined: Tue Oct 07, 2008 9:39 am

Re: Warning when "showexpl" used in conjuction with "hyperref"

Post by fractal.generator »

Dear Mr. Juanjo,

thanks for replying.

Even I used showexpl to present TeX or LaTeX (instead of C#) codes and the formatted text, I still got the same errors.

Please see again the first post in this topic, I had made several modification for the sake of illustration showing caption and hyperref are the cause of the warnings. It is just my prediction.

Anyway, thanks for your explanation above. From yours I know more about listings package. It is useful information.




regards,

hayashi
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Warning when "showexpl" used in conjuction with "hyperref"

Post by Juanjo »

It seems that adding the following line to the preamble, after loading hyperref and showexpl, solves the problem:

Code: Select all

\AtBeginDocument{\renewcommand{\theHlstnumber}{\thelstlisting.\arabic{lstnumber}}}
lstnumber is the counter for numbering listing lines, lstlisting numbers listings, and Hlstnumber is the hyperref internal "clone" of lstnumber, used to generate links. Don't ask why this works. There are things in the kernel of hyperref and showexpl that I don't really understand.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
fractal.generator
Posts: 66
Joined: Tue Oct 07, 2008 9:39 am

Warning when "showexpl" used in conjuction with "hyperref"

Post by fractal.generator »

Dear Mr. Juanjo,

Your code works successfully :!:

Thank you very much. :)

If I use \LTXexample, \LTXinputExample, \lstinputlisting, and \lstlistings, should I use \usepackage{listings} in conjuction with \usepackage{showexpl}? Or It is enough to use \usepackage{showexpl} ONLY?

regards,

Hayashi
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Warning when "showexpl" used in conjuction with "hyperref"

Post by Juanjo »

fractal.generator wrote: If I use \LTXexample, \LTXinputExample, \lstinputlisting, and \lstlistings, should I use \usepackage{listings} in conjuction with \usepackage{showexpl}? Or It is enough to use \usepackage{showexpl} ONLY?
showexpl already loads listings, so it is useless to try to load it again. In fact, LaTeX has a mechanism to read packages only once.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
fractal.generator
Posts: 66
Joined: Tue Oct 07, 2008 9:39 am

Re: Warning when "showexpl" used in conjuction with "hyperref"

Post by fractal.generator »

Thank you very much Mr. Juanjo.

regards,

Hayashi
Post Reply