| 1 |
% This is a mess. |
| 2 |
\def\ptx@label{}% |
| 3 |
\def\label#1{% |
| 4 |
\ifcs{ptx@label_user:#1} |
| 5 |
{\ptx@error{Label `#1' already exists. Find another one}} |
| 6 |
{\global\letcs{ptx@label_user:#1}\relax |
| 7 |
\ptx@label_write{ptx@ref_user:#1}\ptx@label |
| 8 |
\ptx@label_write{ptx@ref_chapter:#1}{\usevalue chapter : internalcount }% |
| 9 |
\ptx@label_write{ptx@ref_section:#1}{\usevalue section : beforenumber \usevalue section : internalcount }% |
| 10 |
\ptx@label_write{ptx@ref_subsection:#1}{\usevalue subsection : beforenumber \usevalue subsection : internalcount }% |
| 11 |
\ptx@label_write{ptx@ref_paragraph:#1}{\usevalue paragraph : beforenumber \usevalue paragraph : internalcount }% |
| 12 |
\iffootnote |
| 13 |
\ptx@label_write{ptx@ref_footnote:#1}{\the\ptx@footnote_count}% |
| 14 |
\fi |
| 15 |
\ptx@write_toaux*{\defcs{ptx@ref_page:#1}{\the\pageno}}}% |
| 16 |
} |
| 17 |
\def\ptx@label_with#1[#2]{% |
| 18 |
\def\ptx@label{#1}% |
| 19 |
\label{#2}% |
| 20 |
\ignorespaces |
| 21 |
} |
| 22 |
\def\ptx@label_and#1[#2]{% |
| 23 |
\label{#2}% |
| 24 |
#1% |
| 25 |
} |
| 26 |
\def\ptx@label_withand#1#2[#3]{% |
| 27 |
\ptx@label_with#1[#3]% |
| 28 |
#2% |
| 29 |
} |
| 30 |
\newif\ifptx@rerun |
| 31 |
\def\ptx@rerun{% |
| 32 |
\unless\ifptx@rerun |
| 33 |
\global\ptx@reruntrue |
| 34 |
\ptx@warn{You need a rerun.}% |
| 35 |
\fi |
| 36 |
} |
| 37 |
\def\ptx@label_write#1#2{% |
| 38 |
\unless\ifptx@rerun |
| 39 |
\edef\ptx@temp{#2}% |
| 40 |
\ifcs{#1} |
| 41 |
{\passexpanded{\passexpandedcs{\reverse\iffstring}{#1}}\ptx@temp\ptx@rerun} |
| 42 |
{\ptx@rerun}% |
| 43 |
\fi |
| 44 |
\ptx@write_toaux{\defcs{#1}{#2}}% |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
\def\ref{% |
| 50 |
\ifnextnospace[ |
| 51 |
{\ptx@ref_getpre} |
| 52 |
{\ptx@ref_getpre[]}% |
| 53 |
} |
| 54 |
\def\ptx@ref_getpre[#1]{% |
| 55 |
\ifnextnospace[ |
| 56 |
{\ptx@ref_getpost{#1}} |
| 57 |
{\ptx@ref_getpost{#1}[]}% |
| 58 |
} |
| 59 |
\def\ptx@ref_getpost#1[#2]#3#{% |
| 60 |
\passtrim{#3}{\ptx@ref_do{#1}{#2}}% |
| 61 |
} |
| 62 |
\def\ptx@ref_do#1#2#3#4{% |
| 63 |
\ifcs{ptx@ref_user:#4} |
| 64 |
{\ifemptystring{#3} |
| 65 |
{\ptx@ref_typeset{\usecs{ptx@ref_user:#4}}} |
| 66 |
{\ifstring{#3}{page}\ptx@refpage_typeset\ptx@ref_typeset{\usecs{ptx@ref_#3:#4}}} |
| 67 |
{#1}{#2}} |
| 68 |
{??\ptx@rerun}% |
| 69 |
} |
| 70 |
\protected\def\ptx@ref_typeset#1#2#3{#2#1#3} |
| 71 |
\newcount\ptx@ref_pagerefcount |
| 72 |
\protected\def\ptx@refpage_typeset#1#2#3{% |
| 73 |
\global\advance\ptx@ref_pagerefcount1 |
| 74 |
\ifcs{ptx@pageref_number:\the\ptx@ref_pagerefcount} |
| 75 |
{\unless\ifnum\usecs{ptx@pageref_number:\the\ptx@ref_pagerefcount}=#1\relax |
| 76 |
#2#1#3% |
| 77 |
\fi} |
| 78 |
{??\ptx@rerun}% |
| 79 |
\expandafter\ptx@pageref_write\expandafter{\the\ptx@ref_pagerefcount}% |
| 80 |
} |
| 81 |
\def\ptx@pageref_write#1{% |
| 82 |
\ptx@write_toaux*{\defcs{ptx@pageref_number:#1}{\the\pageno}}% |
| 83 |
} |
| 84 |
|
| 85 |
\let\xref\ref |
| 86 |
\def\sref{\unskip\ref[ section~][] section} |
| 87 |
\def\Sref{\unskip\ref[ section~][] subsection} |
| 88 |
\def\cref{\unskip\ref[ chapitre~][] chapter} |
| 89 |
\def\pref{\unskip\ref[ (p.~][)] page} |
| 90 |
\def\Pref{\unskip\ref[ p.~][] page} |
| 91 |
\def\fref{\unskip\ref[ figure~][]} |
| 92 |
\def\Fref#1{\fref{#1}\pref{#1}} |
| 93 |
\def\tref{\unskip\ref[ tableau~][]} |
| 94 |
\def\Tref#1{\tref{#1}\pref{#1}} |
| 95 |
\def\fnref{\unskip\ref[ note~][] footnote} |
| 96 |
\def\FNref#1{\fnref{#1}\pref{#1}} |
| 97 |
\def\multiref#1"#2"{% |
| 98 |
\passtrim{#1}{\ptx@multiref_loop{first}{#2}}% |
| 99 |
} |
| 100 |
\def\ptx@multiref#1#2#3{% |
| 101 |
\ptx@multiref_loop{#2}{#3}{#1}% |
| 102 |
} |
| 103 |
\newfor\ptx@multiref_loop{2}#3{% |
| 104 |
\reverse\iffstring{#1}{first}{, }% |
| 105 |
\usecs{#3ref}{#2}% |
| 106 |
\passarguments{}{#2} |
| 107 |
} |