如何在\itshape和之间交替\bfseries

如何在\itshape和之间交替\bfseries

我正在使用reledmac创建自定义环境来排版带有编号行和一些其他功能的诗歌。我设法应用自定义编号并将其重置为之前的状态,以免干扰其他编号部分。

但是,我不知道如何对我通过

\AtStartEveryPstart{\itshape}

到目前为止我所做的就是在环境结束时将其重置为空,但需要的是在开始时存储当前命令并在结束时重新应用它。

首先想到的是通常

\let\tmp\currentMacro

步骤,但当然这行不通,因为我不想储存价值传递给它。

查看reledmac手册后,我发现该值似乎存储在中\@at@start@every@pstart,但我无法存储/检索该值(因为我不了解如何处理这里更多隐藏的术语)。

这是我目前为止所拥有的 MWE 缩减。任何建议或解决方案都值得赞赏:

\documentclass{scrartcl}
\usepackage{reledmac}
\usepackage{blindtext}

% A default style
\AtStartEveryPstart{\bfseries}
\firstlinenum{1}
\linenumincrement{1}
% Default indentation settings
\setstanzaindents{0,0,0}
\setcounter{stanzaindentsrepetition}{1}

% Counters to manage numbering options
\newcounter{stanzafirstline}
\newcounter{stanzainterval}

\newenvironment{poem}{%
\setcounter{stanzafirstline}{\value{firstlinenum}}
\setcounter{stanzainterval}{\value{linenumincrement}}
% Here the current hook definition should be stored
%\let\atformat\@at@start@every@pstart
\AtStartEveryPstart{\itshape}
\beginnumbering
\firstlinenum{4}%     (in real-world 
\linenumincrement{2}% application
\setline{4}%          these areparametrized)
\stanza
}{
\endnumbering
% Here the stored hook should be retrieved
\AtStartEveryPstart{}
\setcounter{firstlinenum}{\value{stanzafirstline}}
\setcounter{linenumincrement}{\value{stanzainterval}}
}
\begin{document}

\beginnumbering
\pstart
\blindtext
\pend
\endnumbering

\blindtext

\begin{poem}
Rosalia von Montanvert&
hieß manchem Troubadour&
und einem ganzen Ritterheer&
die Krone der Natur\&
\end{poem}

\blindtext

\textbf{Note that the line numbering is restored but the boldface hook is not:}

\beginnumbering
\pstart
\blindtext
\pend
\endnumbering

\end{document}

答案1

你的问题有两个问题。

  1. 你真正的问题:如何在 \itshape\bfseries之间交替\AtStartEveryPstart
  2. 您的真正问题(之二):如何将诗歌变为斜体,将散文变为粗体。
  3. 您的技术问题:如何自动检索传递给\AtStartEveryPstart

如何在\itshape和之间交替\bfseries

\AtStartEveryPstart{}在环境结束时,不要使用 made poem,而是直接执行\AtStartEveryPstart{\bfseries}

\documentclass{scrartcl}
\usepackage{reledmac}
\usepackage{blindtext}

% A default style
\AtStartEveryPstart{\bfseries}
\firstlinenum{1}
\linenumincrement{1}
% Default indentation settings
\setstanzaindents{0,0,0}
\setcounter{stanzaindentsrepetition}{1}

% Counters to manage numbering options
\newcounter{stanzafirstline}
\newcounter{stanzainterval}

\newenvironment{poem}{%
\setcounter{stanzafirstline}{\value{firstlinenum}}
\setcounter{stanzainterval}{\value{linenumincrement}}
% Here the current hook definition should be stored
%\let\atformat\@at@start@every@pstart
\AtStartEveryPstart{\itshape}
\beginnumbering
\firstlinenum{4}%     (in real-world
\linenumincrement{2}% application
\setline{4}%          these areparametrized)
\stanza
}{
\endnumbering
% Here the stored hook should be retrieved
\AtStartEveryPstart{\bfseries}
\setcounter{firstlinenum}{\value{stanzafirstline}}
\setcounter{linenumincrement}{\value{stanzainterval}}
}
\begin{document}

\beginnumbering
\pstart
\blindtext
\pend
\endnumbering

\blindtext

\begin{poem}
Rosalia von Montanvert&
hieß manchem Troubadour&
und einem ganzen Ritterheer&
die Krone der Natur\&
\end{poem}

\blindtext

\textbf{Note that the line numbering is restored but the boldface hook is not:}

\beginnumbering
\pstart
\blindtext
\pend
\endnumbering

\end{document}

如何将诗节设为斜体,将诗句设为粗体

不要使用多个时间\AtEveryStartPstart,只需使用ifinstanza内部\AtStartEveryPstart{\ifinstanza\itshape\else\bfseries\fi}

\documentclass{scrartcl}
\usepackage{reledmac}
\usepackage{blindtext}

% A default style
\AtStartEveryPstart{\ifinstanza\itshape\else\bfseries\fi}
\firstlinenum{1}
\linenumincrement{1}
% Default indentation settings
\setstanzaindents{0,0,0}
\setcounter{stanzaindentsrepetition}{1}

% Counters to manage numbering options
\newcounter{stanzafirstline}
\newcounter{stanzainterval}

\newenvironment{poem}{%
\setcounter{stanzafirstline}{\value{firstlinenum}}
\setcounter{stanzainterval}{\value{linenumincrement}}
% Here the current hook definition should be stored
%\let\atformat\@at@start@every@pstart
\beginnumbering
\firstlinenum{4}%     (in real-world
\linenumincrement{2}% application
\setline{4}%          these areparametrized)
\stanza
}{
\endnumbering
% Here the stored hook should be retrieved
\setcounter{firstlinenum}{\value{stanzafirstline}}
\setcounter{linenumincrement}{\value{stanzainterval}}
}
\begin{document}

\beginnumbering
\pstart
\blindtext
\pend
\endnumbering

\blindtext

\begin{poem}
Rosalia von Montanvert&
hieß manchem Troubadour&
und einem ganzen Ritterheer&
die Krone der Natur\&
\end{poem}

\blindtext

\textbf{Note that the line numbering is restored but the boldface hook is not:}

\beginnumbering
\pstart
\blindtext
\pend
\endnumbering

\end{document}

如何自动检索传递给 \AtStartEveryPstart 的值

正如您所注意到的,\AtStartEveryPstart只需将参数值存储在里面\@at@start@every@pstart。您可能注意到,这个命令名包含@。这意味着它是一个内部命令,不能(通常)在文件中访问.tex,而只能在.sty文件中访问。

但是,您可以在.tex文件内部使用\makeatletter\makeatother破解以使用 来访问/定义命令@。这\maketaletter...\makeatother必须包装您的整个环境定义poem,即 TeX 读取行的时间。使用它,您可以\@at@start@every@pstart在备份宏中备份。

您必须处理的第二个问题是,您不想传递给\AtStartEveryPstart备份宏,而是备份宏的扩展。否则,您将陷入无限循环。因此,您必须处理\expandafter

所以

\documentclass{scrartcl}
\usepackage{reledmac}
\usepackage{blindtext}

% A default style
\AtStartEveryPstart{\bfseries}
\firstlinenum{1}
\linenumincrement{1}
% Default indentation settings
\setstanzaindents{0,0,0}
\setcounter{stanzaindentsrepetition}{1}

% Counters to manage numbering options
\newcounter{stanzafirstline}
\newcounter{stanzainterval}

\makeatletter
\newenvironment{poem}{%
\setcounter{stanzafirstline}{\value{firstlinenum}}
\setcounter{stanzainterval}{\value{linenumincrement}}
% Here the current hook definition should be stored
\global\let\@at@start@every@pstart@old\@at@start@every@pstart
\AtStartEveryPstart{\itshape}
\beginnumbering
\firstlinenum{4}%     (in real-world
\linenumincrement{2}% application
\setline{4}%          these areparametrized)
\stanza
}{
\endnumbering
% Here the stored hook should be retrieved
\expandafter\AtStartEveryPstart\expandafter{\@at@start@every@pstart@old}
%Or just do \global\let\@at@start@every@pstart\@at@start@every@pstart@old
\setcounter{firstlinenum}{\value{stanzafirstline}}
\setcounter{linenumincrement}{\value{stanzainterval}}
}
\makeatother
\begin{document}

\beginnumbering
\pstart
\blindtext
\pend
\endnumbering

\blindtext

\begin{poem}
Rosalia von Montanvert&
hieß manchem Troubadour&
und einem ganzen Ritterheer&
die Krone der Natur\&
\end{poem}

\blindtext

\textbf{Note that the line numbering is restored but the boldface hook is not:}

\beginnumbering
\pstart
\blindtext
\pend
\endnumbering

\begin{poem}
Rosalia von Montanvert&
hieß manchem Troubadour&
und einem ganzen Ritterheer&
die Krone der Natur\&
\end{poem}

\blindtext

\textbf{Note that the line numbering is restored but the boldface hook is not:}

\beginnumbering
\pstart
\blindtext
\pend
\endnumbering

\end{document}

答案2

我不知道如何撤回问题,因此我选择回答它(基本上将其标记为“无效”)。

然而我一开始并没有意识到这一点(我做过\itshape尝试类似的东西)只需在环境的开头输入以下内容即可实现我想要的效果

...
\setline{4}
\itshape
\stanza
...

由于某种原因,我的测试结果只有第一节是斜体,所以我最终尝试了段落钩子。上面的代码将斜体应用于整个编号部分,而不会影响外部的任何内容,这正是我想要的。

我仍然有兴趣知道如何检索通过存储的值\AtStartEveryPstart{},但这当然是一个完全不同的问题。

相关内容