将宏扩展为 xparse \SplitList 宏

将宏扩展为 xparse \SplitList 宏

;我曾帮助制作一个宏来处理环境中由分隔的参数列表itemize。为了实现这一点,xparse使用了。

当我尝试将参数列表包装在宏中时,什么也没有发生。我该如何解决这个问题?

梅威瑟:

\documentclass{article}
\usepackage{xparse}
\newcommand\insertitem[1]{\item #1}

% xparse-command I had help with
\NewDocumentCommand\myList{>{\SplitList{;}}m}
  {\vspace*{-\baselineskip}
    \begin{itemize}
      \ProcessList{#1}{ \insertitem }
    \end{itemize}
  }

\newcommand\someStuff{One; two; three}

\begin{document}

\myList{One; two; three}

Now trying to expand macro content

\myList{\someStuff}

\end{document}

结果\myList{One; two; three}如预期的那样,是一个itemized 列表。后一个例子,\myList{\someStuff}不起作用。我相信我的问题的解决方案可能位于问题的某个地方将多个参数从 ProcessList (xparse) 传递到宏。结果将在表格中使用,但我目前无法理解在哪里......

编辑:将参数存储在宏中的预期用途基本上是为了让我的生活更轻松一些。我已经为所教科目的进度计划制定了一个模板结构,例如,我需要在其中打印我的学生在计划期间应该达到的期望主要能力。由于这些能力(以及更多)被包裹在一个混乱的longtable环境中,我计划在有时间学习如何做到这一点时将模板制作成一个类,因此在文档开头有一个看起来像这样的块对我来说非常方便:

\maincompetences{Competence one; competence two, etc.}
\learninggoals{Main goal one; main goal two; etc.}

答案1

TeX 在吸收参数时不会扩展它们。因此在第二种情况下,传递给的参数\SplitArgument\someStuff包含分号。

有人可能会强制扩展参数中的第一个标记,但这可能会产生其他问题。

较低级别的解决方案。

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\myList}{sm}
 {
  \begin{itemize}
  \IfBooleanTF{#1}
   {
    \holene_mylist:o { #2 } % expand the argument (once)
   }
   {
    \holene_mylist:n { #2 }
   }
   \end{itemize}
 }

\seq_new:N \l_holene_mylist_input_seq

\cs_new_protected:Npn \holene_mylist:n #1
 {
  \seq_set_split:Nnn \l_holene_mylist_input_seq { ; } { #1 }
  \seq_map_inline:Nn \l_holene_mylist_input_seq
   {
    \item ##1
   }
 }
\cs_generate_variant:Nn \holene_mylist:n { o }

\ExplSyntaxOff

\newcommand\someStuff{One; two; three}

\begin{document}

\myList{One; two; three}

Now trying to expand macro content

\myList*{\someStuff}

\end{document}

在此处输入图片描述

正在决定何时使用 *-variant 来扩展参数。

相关内容