BaroqueW

and his side-kick nikkitaa

Latex – Comment faire un glossaire ?

with 6 comments

Pour faciliter la lecture de vos rapports techniques, qui foisonnent toujours d’abréviations, il est bon de leur ajouter un glossaire. Ci-dessous, un exemple de document LaTeX avec glossaire. Notez que le chapitre de glossaire n’est pas numéroté (\chapter*) mais apparaît dans la table des matières (\addcontentsline{toc}{chapter}{Glossary}).

\makeglossary
\begin{document}

Ce site est fait en PHP\glossary{[PHP] PHP Hypertext Preprocessor}.

%%%%%%%%%%%
%debut du glossaire%
%%%%%%%%%%%

\chapter*{Glossary}\label{glossary}\addcontentsline{toc}{chapter}{Glossary}

\begin{itemize}
\input{Glossary}
\end{itemize}
\end{document}

Ci-dessous, un script que vous pouvez ajouter à TexShop (MacOSX) pour générer le glossaire proprement. Cliquez sur Macros>Open Macros Editor. Choisissez “New Item” et copiez le script ci-dessous. Associez-lui un raccourci clavier pour régénérer le glossaire rapidement. Pour obtenir le glossaire dans votre pdf, voici la marche à suivre : compilez vos fichiers .tex, compilez votre glossaire et recompilez vos .tex.

--AppleScript direct

set fileName to #NAMEPATH#
set n to (number of characters of contents of fileName)
set fileNamequoted to quoted form of fileName
set baseName to do shell script "basename " & fileNamequoted
set m to (number of characters of contents of baseName)
set dirName to quoted form of (characters 1 thru (n-m-1) of fileName as string)

set shellScript to "cd " & dirName & ";"
set shellScript to shellScript & "./script.sh;"
do shell script shellScript

Notez que le script ci-dessus nécessite la présence d’un fichier “script.sh” dans le dossier contenant vos fichiers .tex. Ce fichier utilise le script PERL “writeglossary.prl” (ci-dessous) pour générer une liste d’items LaTeX à partir des données du glossaire. Il trie ensuite les entrées dans l’ordre alphabétique et élimine les doublons. Pensez à remplacer “Paper.glo” dans le script ci-dessous par ‘Nom de votre fichier’.glo.

#!/bin/tcsh
perl writeglossary.prl Paper.glo > Glossary.tmp
#perl script.pl
perl -e 'while(<>) {push @lines, $_;}warn "\nSorted $. lines in ascending alphabetical order, ignoring case\n\n";print sort {lc($a) cmp lc($b)}@lines' Glossary.tmp > Glossary.tex

Et voilà le fichier “writeglossary.prl”:

# Simple perl script for converting glossary data (*.glo) files produced by
# Latex and converting them to a form suitable for including
# as a Glossary.tex file in a report.
#
# To use:   perl writeglossary.prl filename.glo > Glossary.tex
# Then, in your Latex report file, set up a "description" environment using \begin{description}
# and use \input{Glossary} to import the formatted glossary items.
# (See me310report.tex for example.)
#
# Started 2 August 2006 -mrc
# Note: Macs and Linux usually have perl installed by default. On Windows you might need
# to install it or else use Visual Basic or simply use find/replace in MS Word to
# accomplish the same string replacements as done by this perl script.

############
# Main loop: keep reading new lines until end of file.
# Next line always goes into $_ and pattern matching is done
# on $_ by default.
line: while (<>) {

# Replace any instance of "glossaryentry{" with "item " on every line.
# /g is for global matching (as many times as applies)
s/glossaryentry{/item /g;

#Then take what comes before "}" and throw away the rest.
if(/}/){
$_ = $`;
}

#Append a newline and print to the output.
print($_,"\n");

} # end while(<>)

Written by baroquew

December 8, 2007 at 16:10

6 Responses

Subscribe to comments with RSS.

  1. Bonne idée. Merci

    Anonymous

    December 13, 2007 at 15:09

  2. Thanks so very much for taking your time to create this very useful and informative site. I have learned a lot from your site. Thanks!!

    john

    August 14, 2008 at 22:07

  3. Great Site – really useful information!

    Timmy

    August 22, 2008 at 22:26

  4. Thank for making this valuable information available to the public.s

    Willem

    August 24, 2008 at 20:01

  5. A fantastic site, and brilliant effort. A great piece of work.:

    Timmy

    September 14, 2008 at 05:57

  6. Hello. I think the article is really interesting. I am even interested in reading more. How soon will you update your blog?

    KonstantinMiller

    July 6, 2009 at 21:23


Leave a Reply