我目前尝试用几个键来记录 LaTeX 包。当我使用 tcolorbox 文档库的内部工具时,我得到了一些丑陋的结果。
\documentclass{scrartcl}
\usepackage{showframe}
\usepackage{tcolorbox}
\tcbuselibrary{documentation}
\begin{document}
\begin{docKey}[my/very/long/keypath]{myKey}{=\marg{value}}{}
This is a very very very (very) very long description of the \refKey{/my/very/long/keypath/myKey}
\end{docKey}
\end{document}
引用密钥时,有没有办法只获取最后一部分(密钥本身)?还有其他方法可以在行末中断引用吗?
在搜索了一些文档之后,我发现这部分应该与我的问题相关(第 808 行及以下):
\NewDocumentCommand\tcb@ref@doc{msm}{%
\hyperref[#1:#3]{\texttt{\ref*{#1:#3}}%
\IfBooleanTF{#2}{}{%
\ifnum\getpagerefnumber{#1:#3}=\thepage\relax%
\else%
\textsuperscript{\ding{213}\,\kvtcb@text@pageshort\,\pageref*{#1:#3}}%
\fi}}%
}
\def\refCom{\tcb@ref@doc{com}}
\def\refEnv{\tcb@ref@doc{env}}
\def\refKey{\tcb@ref@doc{key}}
我可能需要一个替代品,它从引用中\ref*{#1:#3}
提取 -separated 列表的最后一个元素/
。但不幸的是,我不知道如何实现这一点。
答案1
对于只获取最后一部分的问题,您可以更新环境docKey
以向定义添加另一个标签,该标签仅打印密钥本身而不打印路径。在下面的 MWE 中,标签定义为*/#1/\kvtcb@doc@label
,因此您可以通过在密钥前加上前缀来引用它*
。
梅威瑟:
\documentclass{scrartcl}
\usepackage{showframe}
\usepackage{tcolorbox}
\tcbuselibrary{documentation}
\makeatletter
\RenewDocumentEnvironment{docKey}{ O{} +O{} m m +m }{\tcbset{doc label={#3},#2,doc description={#5}}%
\begin{tcb@manual@entry}%
\begin{tcb@doc@head}{doc@head@key}%
\ifblank{#1}{%
\tcb@Print@Key{#3}\tcb@index@Key{#3}\protected@edef\@currentlabel{#3}\label{key:\kvtcb@doc@label}{\ttfamily #4}%
}{%
\tcb@Print@Key{/#1/#3}%
\tcb@index@KeyPath{#1}{#3}\protected@edef\@currentlabel{/#1/#3}\label{key:/#1/\kvtcb@doc@label}%
% ADDED LABEL DEFINITION HERE
\protected@edef\@currentlabel{/#3}\label{key:*/#1/\kvtcb@doc@label}%
{\ttfamily #4}%
}%
\tcb@doc@do@description%
\end{tcb@doc@head}\nobreak\tcbset{before upper=}\kvtcb@doc@body@key@before\ignorespaces}%
{\ifvmode\else\unskip\fi\kvtcb@doc@body@key@after\end{tcb@manual@entry}}
\makeatother
\begin{document}
\begin{docKey}[my/very/long/keypath]{myKey}{=\marg{value}}{}
This is a very very very (very) very long description of the \refKey{/my/very/long/keypath/myKey}
This is a very very very (very) very long description of the \refKey{*/my/very/long/keypath/myKey}
\end{docKey}
\end{document}
结果:
请注意,此代码是使用tcolorbox
v4.22 测试的。最新版本 (当前为 4.42) 进行了重大重写,因此此答案中的代码无法立即使用。
为了打破长键,您可以更改环境定义以使用\slash
而不是文字/
,这将允许在斜杠上换行。因为这是一个命令(标签中不允许),所以您应该使用中的键分别定义打印文本(使用\slash
命令)和标签文本(使用文字/
)。doc label
tcolorbox
梅威瑟:
\documentclass{scrartcl}
\usepackage{showframe}
\usepackage{tcolorbox}
\tcbuselibrary{documentation}
\makeatletter
\RenewDocumentEnvironment{docKey}{ O{} +O{} m m +m }{\tcbset{doc label={#3},#2,doc description={#5}}%
\begin{tcb@manual@entry}%
\begin{tcb@doc@head}{doc@head@key}%
\ifblank{#1}{%
\tcb@Print@Key{#3}\tcb@index@Key{#3}\protected@edef\@currentlabel{#3}\label{key:\kvtcb@doc@label}{\ttfamily #4}%
}{%
\tcb@Print@Key{/#1/#3}%
\tcb@index@KeyPath{#1}{#3}\protected@edef\@currentlabel{\slash#1\slash#3}\label{key:\kvtcb@doc@label}%
\protected@edef\@currentlabel{/#3}\label{key:*\kvtcb@doc@label}%
{\ttfamily #4}%
}%
\tcb@doc@do@description%
\end{tcb@doc@head}\nobreak\tcbset{before upper=}\kvtcb@doc@body@key@before\ignorespaces}%
{\ifvmode\else\unskip\fi\kvtcb@doc@body@key@after\end{tcb@manual@entry}}
\makeatother
\begin{document}
\begin{docKey}[my\slash very\slash long\slash keypath][doc label=/my/very/long/keypath/myKey]{myKey}{=\marg{value}}{}
This is a very very very (very) very long description of the \refKey{/my/very/long/keypath/myKey}
This is a very very very (very) very long description of the \refKey{*/my/very/long/keypath/myKey}
\end{docKey}
\end{document}
结果:
答案2
感谢@Marijn 的回答,我能够在当前版本中做出更改,tcolorbox
并希望在这里分享它们:
\ExplSyntaxOn
\cs_gset:Npn \__tcobox_doc_head_key:
{
\__tcobox_print_key:
\__tcobox_index_key:
\tl_if_empty:NTF \kvtcb@doc@keypath
{
\seq_if_in:NVF \g__tcobox_label_seq \kvtcb@doc@label
{
\protected@edef\@currentlabel{\kvtcb@doc@name}
\label{key:\kvtcb@doc@label}
\seq_gput_left:NV \g__tcobox_label_seq \kvtcb@doc@label
}
}
{
\tl_set:Nx \l_tmpa_tl {/\kvtcb@doc@keypath/\kvtcb@doc@label}
\seq_if_in:NVF \g__tcobox_label_seq \l_tmpa_tl
{
% define the short ref
\protected@edef\@currentlabel{/\kvtcb@doc@name}
\label{key:/\kvtcb@doc@keypath/\kvtcb@doc@label}
% define the long one
\protected@edef\@currentlabel{\slash\kvtcb@doc@keypath\slash\kvtcb@doc@name}
\label{key:*/\kvtcb@doc@keypath/\kvtcb@doc@label}
\seq_gput_left:NV \g__tcobox_label_seq \l_tmpa_tl
}
}
{\ttfamily\kvtcb@doc@parameter}
\tcb@doc@do@description
}
\ExplSyntaxOff
这实现了长和短参考标签以及换行功能。