
在我之前的問題沒有得到解答後,我已將 MWE 調整為我認為真正的問題。我有一個儲存資訊的巨集\recent
(這是hyperref
-links 所需的)。當\newone
發出某個命令( )時,該巨集會定期更新(即覆蓋) 。
我想將該巨集的值(即\recent
)儲存在另一個巨集()中的頁面末尾或新頁面的開頭(\previous
)以供參考(我需要它hyperref
在每個頁面上放置一個反向連結)。我幹預了通常的嫌疑犯(everypage
,,,;似乎不喜歡),但不知何故,evershi
-宏很快或在錯誤的時間更新。atbegshi
bophook
hyperref
\previous
請考慮此 MWE 以說明問題。我在使用普通巨集的“”newtoks
之後切換到“ renewcommand{\previous}{\recent}
”沒有成功,但這並沒有幫助解決問題。
\previous
這個想法是在標題中包含真正的“ ”。然而,正如 MWE 所示,事實並非如此。也許有一個非常簡單的解決方案,它可能與發貨機制有關,但我太盲目(而且缺乏經驗)看不到它。
感謝您的每一次幫助。
[這裡的上一個問題:https://tex.stackexchange.com/questions/539473/control-the-referencing-of-labels-in-headlines-hyperref-komascript-or-how-a]
\documentclass[%
12pt,%
twoside=false,%
cleardoublepage=empty,%
open=right,%
parskip=half*,%
headings=normal,%
numbers=noenddot,%
chapterprefix=true,%
%draft %
]{scrbook}
\usepackage[headsepline]{scrlayer-scrpage} \pagestyle{scrheadings}
\clearscrheadfoot
\newcommand{\JumpBackHeadline}{\pagemark -- \the\previous}
\ohead{\JumpBackHeadline}
\usepackage{everypage}
\usepackage{blindtext}
\newtoks{\recent}
\newtoks{\previous}
\global\recent={dummyrecent}
\global\previous={dummyprevious}
\AddEverypageHook{%
previous before EverypageHookoperation: \the\previous\\%
\global\previous={\the\recent}%
previous after EverypageHookoperation: \the\previous
}
\newcommand{\newone}[1]{%
my argument is: #1\\
previous is: \the\previous\\
recent was: \the\recent\\
\global\recent={#1}
recent is: \the\recent
}
\begin{document}
Starting:\\
previous is: \the\previous\\
recent is: \the\recent
\newone{number1}
\blindtext[5]
\newone{number2}
And now lots of text:\\
\blindtext[10]
\newone{number3}
\end{document}
編輯:抱歉造成混亂。希望下面的 MWE 能更好地展示我想要的東西。我關心的不是頁碼,而是連結標籤。我試圖在 MWE 的「問題 1 的答案」中解釋這個概念。也許整個方法是一團糟;如果有人有更好的想法,請隨時發表評論。
\documentclass[
12pt,
twoside=false,
cleardoublepage=empty,
open=right,
parskip=half*,
headings=normal,
numbers=noenddot,
chapterprefix=true,
%draft,
]{scrartcl}
\usepackage{everypage}
\usepackage{blindtext}
\usepackage{marginnote}
\usepackage{ifthen,ragged2e}
\usepackage{hyperref}
%%% The Headline %%%%
\usepackage[headsepline]{scrlayer-scrpage} \pagestyle{scrheadings}
\clearscrheadfoot
\newcommand{\JumpBackHeadline}{% define the headline, depening on JumpBackOn
\ifthenelse{\boolean{JumpBackOn}}%
{\pagemark -- Quick link to
\hyperref[\previous]{\previous}}% Hyperlink only, if jumpback is on
{\pagemark}% %otherwise, i.e. in the questions section, just the
% pagemark
}
\ohead{\JumpBackHeadline}
%% The jump commands to set the hyperlinks
\newboolean{JumpBackOn} % Switch on for jumpback hyperlinks
\setboolean{JumpBackOn}{false} % but not in the first (questions) section
\newcommand{\jumpdown}[1]{\marginnote{\RaggedRight\tiny{\hyperref[#1]{Down
to
#1}}}} % Hyperlink to jump from the question in the questions
% section to the label at the start of the answer in
% the answer section; #1 is this label
\newcommand{\jumpback}[1]{% Jump from the answer to the label at the start of the corresponding question in the questions section; #1 is this label.
\gdef\recent{#1}% Remember this label, it is the label to the question that is currently being discussed.
\marginnote{\RaggedRight\tiny{\hyperref[#1]{Up to
#1}}} % place the hyperlink in the margin
}
%%%% When a page is finished and shipped out: remember the label in
%%%% \recent *at this time* by storing it in \previous
\AddEverypageHook{%
% globally make \previous the same as the current \recent
\global\let\previous=\recent
}
\begin{document}
\section{Questions for students (sometimes very
long)}\setboolean{JumpBackOn}{false}
\begin{enumerate}
\item[1.] Question 1 \label{q:1}\jumpdown{a:1}
\blindtext
\item[2.] Question 2 \label{q:2}\jumpdown{a:2}
\blindtext
\item[3.] Question 3 \label{q:3}\jumpdown{a:3}
\blindtext
\item[4.] Question 4 \label{q:4}\jumpdown{a:4}
\blindtext
\end{enumerate}
\clearpage
\section{Answers, sometimes very
long}\setboolean{JumpBackOn}{true} % From now on, jumpback link in headline
\subsection{Answer to question 1}\label{a:1}\jumpback{q:1}
This is the answer text to question 1. In the margin, a label links
back to question 1; this link is correct. However, as this answer text
extends over a few pages, students should have a quick link in the
headline of each page to jump back to question 1 until answer 1 is
finished. The link should be at the same position in the top or maybe
bottom region of every page; it does not have to be the header, if
this causes trouble.
The link in the headline (or somewhere else) should point to the label
of the question that is (still) discussed \emph{at the beginning of
each page}. In our case, that is question 1 for page 3, 4 and 5.
However, on page 5 there is a link to question 2, not 1. Similarly, on
page 6 there is a link to question 3, not 2, although this question
starts at the top of the next page.
Again, at page 7, the link points to question 4, even though this
question starts at the top of the next page. The link on page 8 is
also wrong, although it appears right: If the previous-linklabel is
fixed at the end of page 7 and this label would then (correctly) point
to question 3, it should point to question 3 at the top of page 8 as
well, although this is not what I want: It is a design failure on my
part, but I have no better idea at the moment. If anyone knows how to
approach the whole thing in a better way, I would be grateful.
\blindtext[9]
\subsection{Answer to question 2}\label{a:2}\jumpback{q:2}
\blindtext[7]
\subsection{Answer to question 3}\label{a:3}\jumpback{q:3}
\blindtext[4]
Some space to fill the page:
\vfill
\subsection{Answer to question 4}\label{a:4}\jumpback{q:4}
\blindtext
\end{document}
答案1
\global\previous={\the\recent}
將要不是傳送 的目前內容\recent
。你應該做
\global\previous=\expandafter{\the\recent}
但我認為使用\global\let
更好。
\documentclass[
12pt,
twoside=false,
cleardoublepage=empty,
open=right,
parskip=half*,
headings=normal,
numbers=noenddot,
chapterprefix=true,
%draft,
]{scrbook}
\usepackage[headsepline]{scrlayer-scrpage} \pagestyle{scrheadings}
\clearscrheadfoot
\newcommand{\JumpBackHeadline}{\pagemark -- \previous}
\ohead{\JumpBackHeadline}
\usepackage{everypage}
\usepackage{blindtext}
\def\recent{dummyrecent}
\def\previous{dummyprevious}
\AddEverypageHook{%
previous before EverypageHookoperation: \previous\\%
% globally make \previous the same as the current \recent
\global\let\previous=\recent
previous after EverypageHookoperation: \previous
}
\newcommand{\newone}[1]{%
my argument is: #1\\
previous is: \previous\\
recent was: \recent\\
\gdef\recent{#1}%
recent is: \recent
}
\begin{document}
Starting:\\
previous is: \previous\\
recent is: \recent
\newone{number1}
\blindtext[5]
\newone{number2}
And now lots of text:
\blindtext[10]
\newone{number3}
\end{document}