0

I came across this post to change the page number 4 to be pi. The proposed solution is the following, which works well for the memoir document class:

\documentclass{memoir}

\usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{blindtext}

\makeatletter \newcommand{@weird}[1]{% \ifnum#1< 4 @arabic{#1}% \else \ifnum#1=4
\texorpdfstring{\large$\pi$}{π}% \else @arabic{\numexpr#1-1}% \fi \fi } \makeatother

\usepackage{hyperref} \begin{document} \frontmatter \tableofcontents \mainmatter \clearpage \pagenumbering{weird} \chapter{First} \blindtext[50] \chapter{Second} \blindtext[50] \end{document}

I tried something similar with the classicthesis style. I'm trying to make certain page numbers bold, e.g. number 4, but the following MWE fails with error messages that I don't understand.

\documentclass[%
    twoside, openright, titlepage, numbers=noenddot,%
    cleardoublepage=empty,%
]{scrreprt}

\PassOptionsToPackage{% dottedtoc,% eulerchapternumbers, floatperchapter, pdfspacing,% beramono,% a5paper,% }{classicthesis} \usepackage{classicthesis}

\usepackage{kantlipsum}

\makeatletter \newcommand{@weird}[1]{% \ifnum#1=4
\texorpdfstring{\textbf{4}}{4}% \else @arabic{\numexpr#1-1}% \fi } \makeatother

\begin{document}

% TOC \pdfbookmark[1]{\contentsname}{tableofcontents}

\pagenumbering{weird} \chapter{Chapter 1} \kant[1-6]

\chapter{Chapter 2} \kant[7-15]

\end{document}

How can I make this work with classicthesis?

kafman
  • 115

2 Answers2

2

classicthesis uses scrlayer-scrpage so you don't need a hack with the page numbering style to change the font of the page number. You can just use \setkomafont:

\documentclass[%
    twoside, openright, titlepage, numbers=noenddot,%
    cleardoublepage=empty,%
]{scrreprt}

\PassOptionsToPackage{% dottedtoc,% eulerchapternumbers, floatperchapter, pdfspacing,% beramono,% a5paper,% }{classicthesis} \usepackage{classicthesis}

\usepackage{kantlipsum}

\makeatletter \setkomafont{pagenumber}{\ifnum \the\c@page=4 \bfseries\fi} \makeatother

\begin{document}

% TOC \pdfbookmark[1]{\contentsname}{tableofcontents}

\chapter{Chapter 1} \kant[1-8]

\chapter{Chapter 2} \kant[9-15]

\end{document}

BTW: scrlayer-scrpage and classicthesis use \pagemark for the page number. So as an alternative you could redefine \pagemark instead of \thepage to change the output of the page number. This would also allow absolutely weird output definitions:

\documentclass[%
    twoside, openright, titlepage, numbers=noenddot,%
    cleardoublepage=empty,%
]{scrreprt}

\PassOptionsToPackage{% dottedtoc,% eulerchapternumbers, floatperchapter, pdfspacing,% beramono,% a5paper,% }{classicthesis} \usepackage{classicthesis}

\usepackage{graphics} \usepackage{kantlipsum}

\makeatletter \ExplSyntaxOn \renewcommand*{\pagemark}{% \fp_set:Nn \l_tmpa_fp { 360 / \c@page } \rotatebox { \fp_to_int:N \l_tmpa_fp } { \usekomafont{pagenumber}{\thepage} } } \ExplSyntaxOff \setkomafont{pagenumber}{\ifnum \the\c@page=3 $\pi$ \expandafter@gobble\fi}% NOTE: You must not use \addtokomafon{pagenumber} after this definition! \makeatother

\begin{document}

% TOC \pdfbookmark[1]{\contentsname}{tableofcontents}

\chapter{Chapter 1} \kant[1-8]

\chapter{Chapter 2} \kant[9-15]

\end{document}

So no need to define weird \thepage to get weird output.

For special cases for several page numbers, it could make sense to use \int_case:nn, e.g.

\setkomafont{pagenumber}
  {
    \int_case:nn { \c@page }
      {
        { 3 } { $\pi$ \use_none:n }
        { 5 } { \ensuremath }
        { 7 } { \bfseries } % \textbf would be possible but a font switch instead of a font command should be preferred
      }
  }

Note that you have to move the \ExplSyntaxOff in the example before behind this command:

\documentclass[%
    twoside, openright, titlepage, numbers=noenddot,%
    cleardoublepage=empty,%
]{scrreprt}

\PassOptionsToPackage{% dottedtoc,% eulerchapternumbers, floatperchapter, pdfspacing,% beramono,% a5paper,% }{classicthesis} \usepackage{classicthesis}

\usepackage{graphics} \usepackage{kantlipsum}

\makeatletter \ExplSyntaxOn \renewcommand*{\pagemark}{% \fp_set:Nn \l_tmpa_fp { 360 / \c@page } \rotatebox { \fp_to_int:N \l_tmpa_fp } { \usekomafont{pagenumber}{\thepage} } } \setkomafont{pagenumber} { \int_case:nn { \c@page } { { 3 } { $\pi$ \use_none:n } { 5 } { \ensuremath } { 7 } { \bfseries } % \textbf would be possible but a font switch instead of a font command should be preferred } } \ExplSyntaxOff \makeatother

\begin{document}

% TOC \pdfbookmark[1]{\contentsname}{tableofcontents}

\chapter{Chapter 1} \kant[1-8]

\chapter{Chapter 2} \kant[9-15]

\end{document}

See The LaTeX3 Interfaces for more information about the l3 functions (and variables) used in the examples above.

Note that only the last font change for element pagenumber is allowed to be a command with argument. Because in this example \@gobble (or \use_none:n) is used to eat the page number, if the page number is 3, you should not use \addtokomafont{pagenumber}{…} after the \setkomafont{pagenumber}{…}.

IMHO redefining \thepage makes only sense, if every usage should be changed, i.e., if also the entries to ToC, LoT, LoF and page references using \pageref should use exactly this output. So it could make sense for output of pi, but IMHO it would not be useful to change the font.

cabohah
  • 11,455
  • Thanks, this seems quite simple, but does this way allow other modifications, e.g. enclosing the page number in math mode? I tried \setkomafont{pagenumber}{\ifnum \the\c@page=3 $\thepage$ \fi} but then it prints the math-mode page number and the original page number. – kafman Nov 02 '23 at 12:14
  • Apologies for not being clear enough in my post - I thought from the answer I could grasp how to make other edits to the page number style in general, but I was wrong. Actually changing the \pagemark instead of \pagenumber is exactly what I want (I don't want the change to appear in the TOC as well). Your solution with the \@gobble works, but only for a single page. I'd like to change several pages, so I tried to add an else statement like \ifnum \the\c@page=3 $\pi$ \expandafter\@gobble \else \ifnum \the\c@page=5 $5$ \expandafter\@gobble \fi \fi but this doesn't work. – kafman Nov 03 '23 at 17:04
  • Again, apologies for not specifying that I need this to work for multiple pages - any chance it can? – kafman Nov 03 '23 at 17:07
  • Thanks for the edits. The \int_case:nn but I can't get the L3 programing layer to work (tried both locally and on overleaf based on this post: https://tex.stackexchange.com/questions/676615/installing-newer-expl3-via-the-tds-zip-file) How would your example with \int_case:nn be translated to use \ifcase? – kafman Nov 04 '23 at 11:37
  • @kafman: ??? You usually don't need to install anything to use \int_case:nn. It is part of LaTeX for years and part of l3 since 2013-07-24. Just copy the code before the \ExplSyntaxOff and remove the other \setkomafont{pagenumber}{…} as shown in my example. If you fail, please ask a new question with minimal working example, that shows, what you've tried and also the error you get. I've already extended my answer too often, because you've asked additional questions in comments instead in new questions. Please avoid such comment provocation of answer extension. – cabohah Nov 04 '23 at 12:08
  • @kafman In other words: Installing a LaTeX3 kernel version >= 2013-07-04 is not part of the question nor can be part of my answer here. Using an out-dated LaTeX without \int_case:nn IMHO even wouldn't be a question for TeX.SX. – cabohah Nov 04 '23 at 12:17
1

If you are doing weirder stuff that cannot be absorbed into simply font choices, you can modify egreg's answer to apply to your case.

\documentclass[%
    twoside, openright, titlepage, numbers=noenddot,%
    cleardoublepage=empty,%
]{scrreprt}

\PassOptionsToPackage{% dottedtoc,% eulerchapternumbers, floatperchapter, pdfspacing,% beramono,% a5paper,% }{classicthesis} \usepackage{classicthesis}

\usepackage{kantlipsum}

\makeatletter \newcommand{@weird}[1]{% \ifnum#1=4
\texorpdfstring{\textbf{4}}{4}% \else @arabic{\numexpr#1-1}% \fi } \renewcommand*\mph@outputpage@hook{% \bgroup \let@weird@arabic % make @weird the same as @arabic, for the purposes of MPH \advance\c@page\m@ne \immediate\write@auxout{% \string\mph@setcol{ii:\thepage}{\string\mph@nr}% }% \egroup } \makeatother

\begin{document} % TOC \pdfbookmark[1]{\contentsname}{tableofcontents}

\pagenumbering{weird} \chapter{Chapter 1} \kant[1-6]

\chapter{Chapter 2} \kant[7-15]

\end{document}

Willie Wong
  • 24,733
  • 8
  • 74
  • 106