编辑1:M(N)WE

编辑1:M(N)WE

我目前正在从 xltabular 迁移到 tabularray。作为迁移的一部分,我想调整我的自定义词汇表样式以适应符号列表和缩写列表(相同样式)。

这是我的旧代码:

% tables
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{xltabular}
\usepackage{tabularray}
\addto\captionsngerman{
    \DefTblrTemplate{contfoot-text}{default}{Fortsetzung auf der n\"achsten Seite}
    \DefTblrTemplate{conthead-text}{default}{(fortgesetzt)}
}

% glossaries
\usepackage[
    abbreviations,
    nonumberlist,
    record,
    symbols
]{glossaries-extra}
\GlsXtrLoadResources[
    src=glossaries,
    not-match={entrytype=symbol}
]
\GlsXtrLoadResources[
    selection=all,
    src=glossaries,
    type=symbols,
    match={entrytype=symbol}
]
\newglossarystyle{customlong}{
    \setglossarystyle{long}
    \renewenvironment{theglossary}{\xltabular{\textwidth}{llX}}{\endxltabular}
    \renewcommand{\glossentry}[2]{
        \glsentryitem{##1}\textbf{\glstarget{##1}{\glossentryname{##1}}} & \multicolumn{2}{X}{\glossentrydesc{##1}}\\
    }
    \renewcommand{\subglossentry}[3]{
        & \glssubentryitem{##2}\glstarget{##2}{\strut} & \glossentrydesc{##2}\\
    }
    \ifglsnogroupskip
        \renewcommand*{\glsgroupskip}{}%
    \else
        \renewcommand*{\glsgroupskip}{\\}%
    \fi
}

我想摆脱:

\usepackage{booktabs}
\usepackage{multirow}
\usepackage{xltabular}

因此,我需要适应\newglossarystyle{customlong}{...}。这是我目前的状态:

\newglossarystyle{customlong}{
    \setglossarystyle{long}
    \renewenvironment{theglossary}{
        \begin{longtblr}[
            entry=none,
            label=none
        ]{
            colspec={llX},
            hspan=minimal,
            stretch=1,
            width=\textwidth
        }
    }{\end{longtblr}}
    \renewcommand{\glossentry}[2]{
        \glsentryitem{##1}\textbf{\glstarget{##1}{\glossentryname{##1}}} & \SetCell[c=2]{l}\glossentrydesc{##1}\\
    }
    \renewcommand{\subglossentry}[3]{
        & \glssubentryitem{##2}\glstarget{##2}{\strut} & \glossentrydesc{##2}\\
    }
    \ifglsnogroupskip
        \renewcommand*{\glsgroupskip}{}%
    \else
        \renewcommand*{\glsgroupskip}{\\}%
    \fi
}

编译失败,提示“对齐制表符 &.”放错位置。当我在和中替换&为时,编译成功,但输出显然包含“&”。\&\renewcommand{\glossentry}[2]{...}\renewcommand{\subglossentry}[3]{...}

我认为这个错误与 tabularray 包文档的以下内容有关:

“与传统的表格环境相比,tabularray 环境在使用 l3regex 拆分表格主体时需要查看每个 & 和 \。并且您不能将单元格文本放在使用 \NewTableCommand 定义的任何表格命令中。但您可以使用外部键展开使 tabularray 在拆分表格主体之前展开指定宏的每个出现位置一次。请注意,您无法展开使用 \NewDocumentCommand 定义的命令。”(https://ftp.gwdg.de/pub/ctan/macros/latex/contrib/tabularray/tabularray.pdf,第 30 页)

这意味着我需要扩展\renewcommand{\glossentry}[2]{...}\renewcommand{\subglossentry}[3]{...}。我不知道如何实现。有人能帮忙吗?

提前致谢。

编辑1:M(N)WE

这是我当前的代码,它打印“&”。一些不相关的内容已被删除。我使用 构建latexmk

主文本

\documentclass{scrbook}

\usepackage{tabularray}

\usepackage[
    abbreviations,
    nonumberlist,
    record,
    symbols
]{glossaries-extra}
\GlsXtrLoadResources[
    src=glossaries,
    not-match={entrytype=symbol}
]
\GlsXtrLoadResources[
    selection=all,
    src=glossaries,
    type=symbols,
    match={entrytype=symbol}
]
\newglossarystyle{customlong}{
    \setglossarystyle{long}
    \renewenvironment{theglossary}{
        \begin{longtblr}[
            entry=none,
            label=none
        ]{
            colspec={llX},
            hspan=minimal,
            stretch=1,
            width=\textwidth
        }
    }{\end{longtblr}}
    \renewcommand{\glossentry}[2]{
        \glsentryitem{##1}\textbf{\glstarget{##1}{\glossentryname{##1}}} \& \SetCell[c=2]{l}\glossentrydesc{##1}\\
    }
    \renewcommand{\subglossentry}[3]{
        \& \glssubentryitem{##2}\glstarget{##2}{\strut} \& \glossentrydesc{##2}\\
    }
    \ifglsnogroupskip
        \renewcommand*{\glsgroupskip}{}%
    \else
        \renewcommand*{\glsgroupskip}{\\}%
    \fi
}
\newglossarystyle{customindex}{
    \setglossarystyle{index}
    \renewcommand{\glstreeitem}{\parindent0pt\par}
    \renewcommand{\glstreepredesc}{\par\glstreeitem\parindent40pt\hangindent40pt}
}

\begin{document}
    \frontmatter
        \printunsrtabbreviations[style=customlong]
        \printunsrtsymbols[style=customlong]

    \mainmatter

    \appendix

    \backmatter
            \printunsrtglossary[style=customindex]
\end{document}

词汇表

@entry{gls-uml,
    name        = {Unified Modeling Language},
    description = {\enquote{A specification defining a graphical language for visualizing, specifying, constructing, and documenting the artifacts of distributed object systems.}\footnote{\url{https://www.omg.org/spec/UML}, aufgerufen am 20.02.2023}.}
}

@abbreviation{auv,
    description = {\gls{gls-auv}},
    short       = {AUV},
    long        = {Autonomous Underwater Vehicle}
}

@symbol{v-desired,
    name        = {\ensuremath{\overrightarrow{v_{desired}}}},
    description = {Wunschgeschwindigkeit}
}

.latexmkrc

@default_files = ('main');

$pdf_mode = 4;
$dvi_mode = 0;
$postscript_mode = 0;

$lualatex = 'lualatex -synctex=1 -interaction=nonstopmode %O %S';

push @generated_exts, 'glstex', 'glg';

$clean_ext .= ' %R.bbl %R.glstex %R.lol %R.run.xml %R-1.glstex ';

add_cus_dep( 'aux', 'glstex', 0, 'run_bib2gls' );

sub run_bib2gls {
        if ($silent) {
                my $ret = system "bib2gls --silent --group $_[0]";
        }
        else {
                my $ret = system "bib2gls --group $_[0]";
        }

        my ( $base, $path ) = fileparse( $_[0] );
        if ( $path && -e "$base.glstex" ) {
                rename "$base.glstex", "$path$base.glstex";
        }

        # Analyze log file.
        local *LOG;
        $LOG = "$_[0].glg";
        if ( !$ret && -e $LOG ) {
                open LOG, "<$LOG";
                while (<LOG>) {
                        if (/^Reading (.*\.bib)\s$/) {
                                rdb_ensure_file( $rule, $1 );
                        }
                }
                close LOG;
        }
        return $ret;
}

相关内容