我想在使用 產生的頁眉內重新定義命令scrheading
。這樣做的原因是頁首應該全部使用小寫字母;但是章節標題恰好包含一個自訂命令,該命令會更改字體大小。我只需要撤銷標題內的字體大小變更。
這是一個 MWE:
\documentclass{scrreprt}
\usepackage[markcase=lower]{scrlayer-scrpage}
\usepackage{graphics}
\usepackage{hyperref}
\newcommand*\lowsc[1]{\texorpdfstring{\protect\scalebox{0.8}{#1}}{#1}}
\pagestyle{scrheadings}
\automark[chapter]{chapter}
\renewcommand*\headfont{%
\scshape%
\renewcommand*\lowsc[1]{##1}}
\newcommand\itex{\lowsc{i}\textsc{tex}}
\begin{document}
\chapter{\itex{} test}
\clearpage
Some text. \itex{}.
\end{document}
這裡的預期輸出是第 2 頁的標題如下:
相反,它看起來像這樣:
如\itex
範例所示,此\lowsc
巨集與 結合使用,以\textsc
小寫字母設定縮寫樣式,但間斷使用小寫字母。如果沒有\lowsc
宏,這些在小型大寫字母旁邊看起來會太大。
裡面\renewcommand*\lowsc
好像\headfont
沒有什麼作用。如果我使用\gdef
(或一些自訂\grenewcommand
巨集)代替,它就可以工作。但是,這重新定義了命令全球,以便正文中的後續用法也發生更改,但這是不應該的。對我來說,這看起來像是一個範圍問題,但老實說,我完全不知道為什麼我的(非全局)重新定義的巨集沒有被應用。
答案1
由於您定義的方式\lowsc
,標頭中的重新定義不起作用,因為 TeX 此時看到的不再是\lowsc
,而是\scalebox{0.8}{i}
。
使用\DeclareRobustCommand
for\lowsc
可以解決問題。不過,我會使用條件。
\documentclass{scrreprt}
\usepackage[markcase=lower]{scrlayer-scrpage}
\usepackage{graphics}
\usepackage{hyperref}
\newif\ifinheader
\DeclareRobustCommand\lowsc[1]{%
\ifinheader
#1%
\else
\texorpdfstring{\scalebox{0.8}{#1}}{#1}%
\fi
}
\pagestyle{scrheadings}
\automark[chapter]{chapter}
\renewcommand*\headfont{%
\scshape\inheadertrue
}
\newcommand\itex{\lowsc{i}\textsc{tex}}
\begin{document}
\chapter{\itex{} test}
\clearpage
Some text. \itex{}.
\end{document}