將巨集展開為 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}

在此輸入影像描述

正在決定是否使用 * 變體擴展參數。

相關內容