]> mj.ucw.cz Git - ucwmac.git/blobdiff - ucwmac2.tex
ucw-ref: Fixed bug in \pageid
[ucwmac.git] / ucwmac2.tex
index e7c48e8287cdd64668dc1a59c42a210e01627f8a..1c29317c8073e402da2f2bca4b07597d72a03f2d 100644 (file)
@@ -24,7 +24,7 @@
        \pdfpkresolution=600    % Provide a reasonable default
 \fi\fi
 
-\ifx\directlua\undefined\else
+\ifx\luatexversion\undefined\else
        % In LuaTeX \pdfpkresolution is not enough
        \directlua{kpse.init_prog("luatex", 600, "ljfour")}
 \fi
 \def\sdef#1{\expandafter\def\csname#1\endcsname}
 \def\slet#1#2{\expandafter\let\csname#1\expandafter\endcsname\csname#2\endcsname}
 
+% Assign a control sequence given as a string, complain if it is not defined.
+\def\sget#1#2{\ifcsname#2\endcsname
+               \expandafter\let\expandafter#1\csname#2\endcsname
+       \else
+               \errmessage{Undefined control sequence #2}%
+               \let#1\relax
+       \fi
+}
+
 % Add \protected to an existing macro
 \def\addprotected#1{\protected\edef#1{\expandafter\unexpanded\expandafter{#1}}}
 
 
 \def\ucwwarn#1{\immediate\write16{*** UCWmac warning: #1 ***}}
 
+% Replace all occurrences of #1 in \tmpb by #2.
+% Thanks to Petr Olsak's OPmac for an efficient implementation.
+\bgroup \catcode`!=3 \catcode`?=3
+\gdef\replacestrings#1#2{\long\def\replacestringsA##1#1{\def\tmpb{##1}\replacestringsB}%
+   \long\def\replacestringsB##1#1{\ifx!##1\relax \else\appendef\tmpb{#2##1}%
+      \expandafter\replacestringsB\fi}%
+   \expandafter\replacestringsA\tmpb?#1!#1%
+   \long\def\replacestringsA##1?{\def\tmpb{##1}}\expandafter\replacestringsA\tmpb
+}
+\egroup
+
 %%% Page size and margins %%%
 
 % If you modify these registers, call \setuppage afterwards
 \ifx\luatexversion\undefined
        % In LuaTeX, \pagewidth and \pageheight are primitive
-       \newdimen\pagewidth
-       \newdimen\pageheight
+       % (also, we need \csname here, because \newdimen is \outer)
+       \csname newdimen\endcsname\pagewidth
+       \csname newdimen\endcsname\pageheight
 \fi
 \newdimen\leftmargin
 \newdimen\rightmargin
 %      #.              % with a dot behind
 %      #)              % with a parenthesis behind
 %      (#)             % enclosed in parentheses
+%      [#]             % enclosed in square brackets
 %
 % Historic usage:
 %
 \def\liststyle#1{%
        \edef\markertmp{#1}
        \ifcsname item:\markertmp\endcsname
-               \slet{listmarker}{item:\markertmp}%
+               \sget\listmarker{item:\markertmp}%
        \else
-               \slet{listmarker}{metaitem:\markertometa#1^^X}%
-               \slet{markerinner}{item:\markertoinner#1^^X}%
+               \sget\listmarker{metaitem:\markertometa#1^^X}%
+               \sget\markerinner{item:\markertoinner#1^^X}%
        \fi
 }
 
        \ifx#1^^X%
        \else
                \ifx#1((%
+               \else\ifx#1[[%
                \else\ifx#1))%
+               \else\ifx#1]]%
                \else\ifx#1..%
                \else=%
-               \fi\fi\fi
+               \fi\fi\fi\fi\fi
                \expandafter\markertometa
        \fi
 }
        \else
                \ifx#1(%
                \else\ifx#1)%
+               \else\ifx#1[%
+               \else\ifx#1]%
                \else\ifx#1.%
                \else#1%
-               \fi\fi\fi
+               \fi\fi\fi\fi\fi
                \expandafter\markertoinner
        \fi
 }
 
+\def\endlist{\par\endgroup\postitemize}
+
+% List styles
+\sdef{item:o}{\raise0.2ex\hbox{$\bullet$}}
+\sdef{item:O}{\raise0.2ex\hbox{$\circ$}}
+\sdef{item:*}{\raise0.2ex\hbox{$\ast$}}
+\sdef{item:-}{--}
+\sdef{item:.}{\raise0.2ex\hbox{$\cdot$}}
+\sdef{item:n}{\the\itemcount}
+\sdef{item:i}{\romannumeral\itemcount}
+\sdef{item:I}{\uppercase\expandafter{\romannumeral\itemcount}}
+\sdef{item:a}{\char\numexpr 96+\itemcount\relax}
+\sdef{item:A}{\char\numexpr 64+\itemcount\relax}
+\sdef{item:g}{$\ifcase\itemcount\or\alpha\or\beta\or\gamma\or\delta\or\epsilon\or
+\zeta\or\eta\or\theta\or\iota\or\kappa\or\lambda\or\mu\or\nu\or\xi\or\pi\or\rho
+\or\sigma\or\tau\or\upsilon\or\phi\or\chi\or\psi\or\omega\fi$}
+
+% List meta-styles
+\sdef{metaitem:=.}{\markerinner.}
+\sdef{metaitem:=)}{\markerinner)}
+\sdef{metaitem:(=)}{(\markerinner)}
+\sdef{metaitem:[=]}{[\markerinner]}
+
+% Old-style lists
+
 \def\itemize#1{\inititemize\setbox\itembox\llap{#1\hskip\itemmarkerskip}%
 \let\:=\singleitem}
 
 \def\singleitem{\par\leavevmode\copy\itembox\ignorespaces}
 
-\def\endlist{\par\endgroup\postitemize}
-
-% Markers for \itemize
-\def\ibull{\raise0.2ex\hbox{$\bullet$}}
-\def\idot{\raise0.2ex\hbox{$\cdot$}}
-\def\istar{\raise0.2ex\hbox{$\ast$}}
-
 \def\numlist#1{\inititemize\itemcount=0\let\:=\numbereditem
 \let\itemnumbering=#1}
 
 \def\numbereditem{\par\leavevmode\advance\itemcount by 1
 \llap{\itemnumbering\hskip\itemmarkerskip}\ignorespaces}
 
-% Numbering styles for \numlist
+% Old-style markers
+
+\def\ibull{\raise0.2ex\hbox{$\bullet$}}
+\def\idot{\raise0.2ex\hbox{$\cdot$}}
+\def\istar{\raise0.2ex\hbox{$\ast$}}
+
 \def\nnorm{\the\itemcount}
 \def\ndotted{\nnorm.}
 \def\nparen{\nnorm)}
 \zeta\or\eta\or\theta\or\iota\or\kappa\or\lambda\or\mu\or\nu\or\xi\or\pi\or\rho
 \or\sigma\or\tau\or\upsilon\or\phi\or\chi\or\psi\or\omega\fi$)}
 
-% List styles
-\sdef{item:o}{\raise0.2ex\hbox{$\bullet$}}
-\sdef{item:O}{\raise0.2ex\hbox{$\circ$}}
-\sdef{item:*}{\raise0.2ex\hbox{$\ast$}}
-\sdef{item:-}{--}
-\sdef{item:.}{\raise0.2ex\hbox{$\cdot$}}
-\sdef{item:n}{\the\itemcount}
-\sdef{item:i}{\romannumeral\itemcount}
-\sdef{item:I}{\uppercase\expandafter{\romannumeral\itemcount}}
-\sdef{item:a}{\char\numexpr 96+\itemcount\relax}
-\sdef{item:A}{\char\numexpr 64+\itemcount\relax}
-\sdef{item:g}{$\ifcase\itemcount\or\alpha\or\beta\or\gamma\or\delta\or\epsilon\or
-\zeta\or\eta\or\theta\or\iota\or\kappa\or\lambda\or\mu\or\nu\or\xi\or\pi\or\rho
-\or\sigma\or\tau\or\upsilon\or\phi\or\chi\or\psi\or\omega\fi$}
-
-% List meta-styles
-\sdef{metaitem:=.}{\markerinner.}
-\sdef{metaitem:=)}{\markerinner)}
-\sdef{metaitem:(=)}{(\markerinner)}
-
 %%% Miscellanea %%%
 
 % {\I italic} with automatic italic correction