From 1b3a0d2fd41be6da2783900f7e03472c9f8f6c1e Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Wed, 9 Nov 2022 21:07:39 +0000 Subject: fancyhdr (9nov22) git-svn-id: svn://tug.org/texlive/trunk@64977 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/source/latex/fancyhdr/fancyhdr.dtx | 206 ++++++++++++++++----- 1 file changed, 164 insertions(+), 42 deletions(-) (limited to 'Master/texmf-dist/source/latex/fancyhdr') diff --git a/Master/texmf-dist/source/latex/fancyhdr/fancyhdr.dtx b/Master/texmf-dist/source/latex/fancyhdr/fancyhdr.dtx index 9c7a90992ed..2995092da6a 100644 --- a/Master/texmf-dist/source/latex/fancyhdr/fancyhdr.dtx +++ b/Master/texmf-dist/source/latex/fancyhdr/fancyhdr.dtx @@ -26,7 +26,7 @@ %\ProvidesPackage{fancyhdr}% %\ProvidesPackage{fancyheadings} %\ProvidesPackage{extramarks} -% [2022/05/18 v4.0.3 +% [2022/11/09 v4.1 % Extensive control of page headers and footers]% % Legacy package to call fancyhdr] % Extra marks for LaTeX] @@ -139,22 +139,22 @@ } \fancypagestyle{showstruts}{% \fancyhead[L]{% - \ifthenelse{\value{page}=\pageref{showstruts}}% + \ifthenelse{\value{page}=\getpagerefnumber{showstruts}}% {\strutheader}% {\rightmark}% } \fancyfoot[L]{% - \ifthenelse{\value{page}=\pageref{showstruts}}% + \ifthenelse{\value{page}=\getpagerefnumber{showstruts}}% {\strutfooter}% {}% } \fancyheadinit{% - \ifthenelse{\value{page}=\pageref{showstruts}}% + \ifthenelse{\value{page}=\getpagerefnumber{showstruts}}% {\renewcommand{\headruleskip}{4pt}}% {\renewcommand{\headruleskip}{0pt}}% } \fancyfootinit{% - \ifthenelse{\value{page}=\pageref{showstruts}}% + \ifthenelse{\value{page}=\getpagerefnumber{showstruts}}% {\renewcommand{\footrulewidth}{0.4pt}}% {\renewcommand{\footrulewidth}{0pt}}% } @@ -291,6 +291,8 @@ % \texttt{compatV3} & keep some behaviour (now considered undesirable) as in version~3 \\ % & (see section~\ref{sec:options} and section~\ref{sec:warning} on % page~\pageref{page:warning}) \\ +% \texttt{twoside} & use two-sided headers and footers even in one-sided documents \\ +% & for \Package{fancyhdr}-based pagestyles (version 4.1 or later) \\ % \texttt{headings} & redefine the \texttt{headings} page style to be fancy-based \\ % \texttt{myheadings} & redefine the \texttt{myheadings} page style to be fancy-based \\ % \bottomrule @@ -298,6 +300,7 @@ % \end{center} % \OPTindex{nocheck} % \OPTindex{compatV3} +% \OPTindex{twoside} % \OPTindex{headings} % \OPTindex{myheadings} % \DescribeMacro{\fancyhead} @@ -353,7 +356,7 @@ % \cs{fancyheadinit} and \cs{fancyfootinit} can be used to define % initialisation code for the header and footer, respectively, and % \cs{fancyhfinit} defines both of these. These commands are only -% available in fancyhdr version~4.0 and later. See section~\ref{sec:change}. +% available in \Package{fancyhdr} version~4.0 and later. See section~\ref{sec:change}. % % \DescribeMacro{\fancycenter} % (Only in version~4.0 and later.) The command \cs{fancycenter} packs 3 @@ -465,11 +468,11 @@ % % The margin notes % area contains small pieces of information created by the \cs{marginpar} -% command. On twosided documents the margin notes appear on the left and right +% command. On two-sided documents the margin notes appear on the left and right % alternatively. The margin notes are not on fixed places with respect to the % paper but at approximately the same height as the paragraph in which they % appear. Due to the algorithm used to decide the placement of margin notes, -% in a twosided document unfortunately +% in a two-sided document unfortunately % they may appear on the wrong side if they are close % to a page break. % If you want to put information on fixed places in the margins you may use @@ -571,7 +574,7 @@ % and lowercase displays, etc. % % \section{Simple use of \Package{fancyhdr}} To use this package -% install it is a place where \latex/ can find it (see +% install it in a place where \latex/ can find it (see % section~\ref{sec:installation})\footnote{In most modern \tex/ % installation the package is already included.}, and include in the preamble of your document % the commands: @@ -957,13 +960,15 @@ % \end{quote} % % The following options are supported: % \begin{center} -% \OPTindex{nocheck}\OPTindex{compatV3}\OPTindex{headings}\OPTindex{myheadings} +% \OPTindex{nocheck}\OPTindex{compatV3}\OPTindex{twoside}\OPTindex{headings}\OPTindex{myheadings} % \begin{tabular}{ l l } % \toprule % Option & Meaning \\ % \midrule % \texttt{nocheck} & do not check the heights of the header and footer \\ % \texttt{compatV3} & keep some behaviour (now considered undesirable) as in version~3 \\ +% \texttt{twoside} & use two-sided headers and footers even in one-sided documents \\ +% & for \Package{fancyhdr}-based pagestyles (version 4.1 or later) \\ % \texttt{headings} & redefine the \texttt{headings} page style to be fancy-based \\ % \texttt{myheadings} & redefine the \texttt{myheadings} page style to be fancy-based \\ % \bottomrule @@ -996,6 +1001,13 @@ % The option is scheduled to disappear in version~5 of % \Package{fancyhdr}. % +% \item \OPTindex{twoside}Option \texttt{twoside} implements two-sided headers +% and footers in one-sided documents (version 4.1 or later). This applies only +% for \Package{fancyhdr}-based pagestyles. This option doesn't do anything +% special for two-sided documents (\texttt{twoside} documentclass option), as +% these already have that functionality. And with the \texttt{twoside} +% documentclass option that does apply to other pagestyles as well. +% % \item \PSindex{headings}\PSindex{myheadings}\OPTindex{headings}\OPTindex{myheadings} % The options \texttt{headings} and \texttt{myheadings} redefine the % corresponding page style with fancyhdr commands (including a @@ -1167,7 +1179,7 @@ % and footer fields. Note that this may screw other things, like uppercase % roman numerals in your headers, so it should be used with care. Essentially % this command typesets its argument in an environment where -% \cs{MakeUppercase} and \cs{uppercase} are changed into do-nothing operations. +% \cs{MakeUppercase} and \cs{uppercase} are changed into identity operations. % % ^^A \Example % \begin{verbatim} @@ -1758,6 +1770,7 @@ % Some document writers prefer the pages to be numbered as \textsf{n} of % \textsf{m} where \textsf{m} is the number of pages in the document. % There is a package \Package{lastpage} +% \TTindex{lastpage} % available which you can use with \Package{fancyhdr} as follows: % % \begin{verbatim} @@ -1774,18 +1787,28 @@ % We clear all the headers including its rule. The footer will be % ``inherited'' from the pagestyle \texttt{fancy}. % -% The value of the \texttt{LastPage} label can be used to +% The value of the \texttt{LastPage}\TTindex{LastPage} label can be used to % make different headers or footers on the last page of a document. E.g.\ if % you want the footer of every odd page, except if it is the last one, to -% contain the text ``please turn over'', this can be done as -% follows: +% contain the text ``Please turn over'', this can be done by checking if +% the page number is odd, and if it is equal to the number of the last page. +% +% We use the macro \cs{getpagerefnumber} from the package\TTindex{refcount} +% \Package{refcount}, because \cs{pageref} isn't always usable in a +% numerical context (it is meant for typesetting only). This is also done in +% following similar examples. % +% \TTindex{ifthen}\TTindex{lastpage}\TTindex{refcount} % \begin{verbatim} -% \usepackage{lastpage} % \usepackage{ifthen} +% \usepackage{lastpage} +% \usepackage{refcount} % ... -% \fancyfoot[R]{\ifthenelse{\isodd{\value{page}} \and \not -% \(\value{page}=\pageref{LastPage}\)}{please turn over}{}} +% \fancyfoot[R]{% +% \ifthenelse{\isodd{\value{page}} \and +% \not \( \value{page}=\getpagerefnumber{LastPage} \) }% +% {Please turn over}{}% +% } % \end{verbatim} % % In order to get the number of pages correctly used, you usually have @@ -2022,12 +2045,14 @@ % \end{verbatim} % ^^A\Example % we define a new pagestyle that makes the choice: +% \TTindex{ifthen}\TTindex{refcount} % \begin{verbatim} % \usepackage{ifthen} +% \usepackage{refcount} % . . . % \fancypagestyle{switch}{ % \fancyhead[LE,RO]{% -% \ifthenelse{\value{page}=\pageref{otherpagestyle}} +% \ifthenelse{\value{page}=\getpagerefnumber{otherpagestyle}} % {MYFANCY SECTION} % {\textsl{\rightmark}}} % } @@ -2085,7 +2110,7 @@ % \begin{verbatim} % %%% NOTE: This does not work %%%% % \renewcommand{\footrulewidth}{% -% \ifthenelse{\value{page}=\pageref{otherpagestyle}}{0.4pt}{0pt}% +% \ifthenelse{\value{page}=\getpagerefnumber{otherpagestyle}}{0.4pt}{0pt}% % } % \end{verbatim} % For cases like this \Package{fancyhdr} version~4.0 and later has some @@ -2103,15 +2128,16 @@ % \cs{footrulewidth} depending on the page number. So instead of putting % the test inside the definition of \cs{headruleskip}, we can put it % outside, and then we can use the command \cs{ifthenelse}. So we put -% the following in \Cmd{pagestyle\{switch\}}: +% the following in \Cmd{pagestyle\{switch\}}\footnote{Assuming we have +% already loaded package \Package{refcount}.}: % \begin{verbatim} % \fancyheadinit{% -% \ifthenelse{\value{page}=\pageref{otherpagestyle}} +% \ifthenelse{\value{page}=\getpagerefnumber{otherpagestyle}} % {\renewcommand{\headruleskip}{4pt}} % {\renewcommand{\headruleskip}{0pt}} % } % \fancyfootinit{% -% \ifthenelse{\value{page}=\pageref{otherpagestyle}} +% \ifthenelse{\value{page}=\getpagerefnumber{otherpagestyle}} % {\renewcommand{\footrulewidth}{0.4pt}} % {\renewcommand{\footrulewidth}{0pt}} % } @@ -2120,22 +2146,22 @@ % \begin{verbatim} % \fancypagestyle{showstruts}{% % \fancyhead[L]{% -% \ifthenelse{\value{page}=\pageref{showstruts}}% +% \ifthenelse{\value{page}=\getpagerefnumber{showstruts}}% % {\strutheader}% % {\rightmark}% % } % \fancyfoot[L]{% -% \ifthenelse{\value{page}=\pageref{showstruts}}% +% \ifthenelse{\value{page}=\getpagerefnumber{showstruts}}% % {\strutfooter}% % {}% % } % \fancyheadinit{% -% \ifthenelse{\value{page}=\pageref{showstruts}}% +% \ifthenelse{\value{page}=\getpagerefnumber{showstruts}}% % {\renewcommand{\headruleskip}{4pt}}% % {\renewcommand{\headruleskip}{0pt}}% % } % \fancyfootinit{% -% \ifthenelse{\value{page}=\pageref{showstruts}}% +% \ifthenelse{\value{page}=\getpagerefnumber{showstruts}}% % {\renewcommand{\footrulewidth}{0.4pt}}% % {\renewcommand{\footrulewidth}{0pt}}% % } @@ -2156,11 +2182,11 @@ % header and/or footer, for example to get large, red text in the % headers and footers on this specific page: % \begin{verbatim} -% \fancyhfinit{% -% \ifthenelse{\value{page}=\pageref{otherpagestyle}} -% {\color{red}\Large} -% {} -% } +% \fancyhfinit{% +% \ifthenelse{\value{page}=\getpagerefnumber{otherpagestyle}} +% {\color{red}\Large} +% {} +% } % \end{verbatim} % % \subsection{Changing the page style of the next page} @@ -2998,6 +3024,13 @@ % \item Initialize \cs{@mkboth} in \texttt{extramarks.sty} so that % it will pick up changes to \cs{markboth}. % \end{itemize} +% \item Version 4.1, Sept 6-Nov 9, 2022 +% \begin{itemize} +% \item Implement \texttt{twoside} package option to allow two-sided headers +% and footers in one-sided documents. +% \item Make \Package{fancyhdr} compatible with the document class \Package{newlfm}. +% \item Make \cs{nouppercase} compatible with newer definitions of \cs{MakeUppercase}. +% \end{itemize} % \end{itemize} % % @@ -3305,7 +3338,7 @@ % A check for \cs{headheight} is added. An errormessage is given (once) if the % header is too large. Empty headers don't generate the error even if % \cs{headheight} is very small or even 0pt. \\ -% Warning added for the use of '\texttt{E}' option when twoside option is not used. +% Warning added for the use of '\texttt{E}' option when \texttt{twoside} option is not used. % In this case the '\texttt{E}' fields will never be used.} % % \changes{fancyhdr v2.1beta}{2002/03/10}{New command: @@ -3408,6 +3441,20 @@ % \end{macro} % \end{macro} % +% \begin{macro}{\iff@nch@twoside} +% Boolean for the \texttt{twoside} option. +% \changes{fancyhdr v4.1}{2022/09/06}{Implement \texttt{twoside} option.} +% \OPTindex{twoside} +% This is only set if the document itself is not two-sided. +% \begin{macrocode} +\newif\iff@nch@twoside +\f@nch@twosidefalse +\DeclareOption{twoside}{% + \if@twoside\else\f@nch@twosidetrue\fi +} +% \end{macrocode} +% \end{macro} +% % \begin{macro}{\f@nch@def} % This macro defines another macro (usually a header or footer field). % Depending on the value of \cs{f@nch@gbl} the definition will be @@ -3688,8 +3735,21 @@ % \end{macro} % \end{macro} % +% \begin{macro}{\f@nch@fancyhf@Echeck} +% \changes{fancyhdr v4.1}{2022/09/06}{Implement \texttt{twoside} option.} +% Macro for warning if `E' is used without `twoside' option. +% \begin{macrocode} +\def\f@nch@fancyhf@Echeck#1{% + \if@twoside\else + \iff@nch@twoside\else + \if\f@nch@@eo e% + \f@nch@warning {\string#1's `E' option without twoside option is useless.\MessageBreak + Please consider using the `twoside' option}% + \fi\fi\fi +} % \begin{macro}{\f@nch@fancyhf} % \changes{fancyhdr v4.0.2}{2022/05/10}{Make \cs{f@nch@fancyhf} \cs{long}.} +% \changes{fancyhdr v4.1}{2022/09/06}{Implement \texttt{twoside} option.} % This macro interprets the parameters for the headers and footers.\\ % Parameters:\\ % (1) The user command that was used (like \cs{fancyhead}). This is used @@ -3711,9 +3771,9 @@ \ifx\@empty\temp@c\else \f@nch@errmsg{Illegal char `\temp@c' in \string#1 argument: [#3]}% \fi \f@nch@for\temp@c{#3}% - {\f@nch@default\f@nch@@eo{eo}\temp@c \if@twoside\else \if\f@nch@@eo - e\f@nch@warning {\string#1's `E' option without twoside option is - useless}\fi\fi \f@nch@default\f@nch@@lcr{lcr}\temp@c + {\f@nch@default\f@nch@@eo{eo}\temp@c + \f@nch@fancyhf@Echeck{#1}% + \f@nch@default\f@nch@@lcr{lcr}\temp@c \f@nch@default\f@nch@@hf{hf}{#2\temp@c}% \f@nch@forc\f@nch@eo\f@nch@@eo {\f@nch@forc\f@nch@lcr\f@nch@@lcr @@ -3724,6 +3784,7 @@ % \end{macro} % % \begin{macro}{\f@nch@fancyhfoffs} +% \changes{fancyhdr v4.1}{2022/09/06}{Implement \texttt{twoside} option.} % This macro interprets the parameters for the header and footer % offsets.\\ % Parameters:\\ @@ -3746,9 +3807,9 @@ \ifx\@empty\temp@c\else \f@nch@errmsg{Illegal char `\temp@c' in \string#1 argument: [#3]}% \fi \f@nch@for\temp@c{#3}% - {\f@nch@default\f@nch@@eo{eo}\temp@c \if@twoside\else \if\f@nch@@eo - e\f@nch@warning {\string#1's `E' option without twoside option is - useless}\fi\fi \f@nch@default\f@nch@@lcr{lr}\temp@c + {\f@nch@default\f@nch@@eo{eo}\temp@c + \f@nch@fancyhf@Echeck{#1}% + \f@nch@default\f@nch@@lcr{lr}\temp@c \f@nch@default\f@nch@@hf{hf}{#2\temp@c}% \f@nch@forc\f@nch@eo\f@nch@@eo {\f@nch@forc\f@nch@lcr\f@nch@@lcr @@ -3943,14 +4004,27 @@ % their default values (for tabu), and \cs{everypar} to empty.\\ % The font is reset to \cs{normalfont}. Actually this is done in the % \LaTeX{} output routine, so we don't have to do it here. +% \changes{fancyhdr v4.1}{2022/11/09}{Change \cs{nouppercase} to work with +% new definition of \cs{MakeUppercase}.} +% \begin{macro}{\f@nch@noUppercase} +% We want \cs{nouppercase} to work with the various evolutionary stages of +% \cs{MakeUppercase}. The current version (2022/11/09) accepts an optional +% argument with a language specification. Therefore we define a dummy macro +% \cs{f@nch@noUppercase} which copies its mandatory agument, as a +% replacement for \cs{MakeUppercase} while \cs{nouppercase} is active. % \begin{macrocode} +\newcommand\f@nch@noUppercase[2][]{#2} \def\f@nch@reset{\f@nch@everypar{}\restorecr\endlinechar=13 \let\\\@normalcr \let\raggedleft\f@nch@raggedleft \let\raggedright\f@nch@raggedright \let\centering\f@nch@centering \def\baselinestretch{1}% \hsize=\headwidth - \def\nouppercase##1{{\let\uppercase\relax\let\MakeUppercase\relax - \expandafter\let\csname MakeUppercase \endcsname\relax##1}}% + \def\nouppercase##1{{% + \let\uppercase\relax\let\MakeUppercase\f@nch@noUppercase + \expandafter\let\csname MakeUppercase \endcsname\relax + \expandafter\def\csname MakeUppercase\space\space\space\endcsname + [####1]####2{####2}% + ##1}}% \f@nch@ifundefined{@newbaseline} % NFSS not present; 2.09 or 2e {\f@nch@ifundefined{@normalsize} {\normalsize} % for ucthesis.cls {\@normalsize}}% @@ -3958,6 +4032,7 @@ } % \end{macrocode} % \end{macro} +% \end{macro} % % \begin{macro}{\fancycenter} % \changes{fancyhdr v4.0}{2019/03/15}{Macro \cs{fancycenter} added} @@ -4392,6 +4467,7 @@ % % \begin{macro}{\ps@f@nch@fancycore} % \changes{fancyhdr v4.0}{2019/03/21}{Rename \cs{ps@@fancy} to \cs{ps@f@nch@fancycore}} +% \changes{fancyhdr v4.1}{2022/09/06}{Implement \texttt{twoside} option.} % The actual implementation of pagestyle \texttt{fancy}. For amsbook/amsart, which do % strange things with \cs{topskip}, we start with \cs{f@nch@ps@empty}. We % construct the even and odd headers and footers from all the parts that @@ -4400,8 +4476,30 @@ \def\ps@f@nch@fancycore{% \f@nch@ps@empty \def\@mkboth{\protect\markboth}% - \def\@oddhead{\f@nch@head\f@nch@Oolh\f@nch@olh\f@nch@och\f@nch@orh\f@nch@Oorh}% - \def\@oddfoot{\f@nch@foot\f@nch@Oolf\f@nch@olf\f@nch@ocf\f@nch@orf\f@nch@Oorf}% + \def\f@nch@oddhead{\f@nch@head\f@nch@Oolh\f@nch@olh\f@nch@och\f@nch@orh\f@nch@Oorh}% + \def\@oddhead{% + \iff@nch@twoside + \ifodd\c@page + \f@nch@oddhead + \else + \@evenhead + \fi + \else + \f@nch@oddhead + \fi + } + \def\f@nch@oddfoot{\f@nch@foot\f@nch@Oolf\f@nch@olf\f@nch@ocf\f@nch@orf\f@nch@Oorf}% + \def\@oddfoot{% + \iff@nch@twoside + \ifodd\c@page + \f@nch@oddfoot + \else + \@evenfoot + \fi + \else + \f@nch@oddfoot + \fi + } \def\@evenhead{\f@nch@head\f@nch@Oelh\f@nch@elh\f@nch@ech\f@nch@erh\f@nch@Oerh}% \def\@evenfoot{\f@nch@foot\f@nch@Oelf\f@nch@elf\f@nch@ecf\f@nch@erf\f@nch@Oerf}% } @@ -4567,6 +4665,30 @@ }% % \end{macrocode} % \end{macro} +% \changes{fancyhdr v4.1}{202/09/16}{Support for class \Package{newlfm}.} +% The (really outdated) document class \Package{newlfm} uses some internal +% \Package{fancyhdr} commands that have gotten new names. So here we check if +% that class is loaded and then we redefine the affected \Package{newlfm} macros. +% We have to do some of the redefinitions in \cs{AtBeginDocument}, as +% \Package{fancyhdr} is loaded before the affected macros are defined. Also +% the macro \cs{@zfancyhead} is only called once, with wrong (outdated) +% parameters, so instead of changing the call of the macro, we substitute the +% right parameters inline. +% \begin{macrocode} +\@ifclassloaded{newlfm} +{ + \let\ps@@empty\f@nch@ps@empty + \AtBeginDocument{% + \renewcommand{\@zfancyhead}[5]{\relax\hbox to\headwidth{\f@nch@reset + \@zfancyvbox\headheight{\hbox + {\rlap{\parbox[b]{\headwidth}{\raggedright\f@nch@olh}}\hfill + \parbox[b]{\headwidth}{\centering\f@nch@olh}\hfill + \llap{\parbox[b]{\headwidth}{\raggedleft\f@nch@orh}}}% + \zheadrule}}\relax}% + } +} +{} +% \end{macrocode} % % % \section{extramarks.sty} -- cgit v1.2.3