在 itemize + 字符串数组中进行 For 循环

在 itemize + 字符串数组中进行 For 循环

考虑一个文档,其中有几个部分包含列表。内容是可预测的;列表前面有一个小序言。如下所示:

\documentclass{article}%

% BASIC QUALIFICATIONS

\def\qualificationa{A degree}%
\def\qualificationb{Skill}%
\def\qualificationc{Common sense}%
%\def\qualificationd{Enthusiasm}%

\begin{document}

% duties
\section*{Basic Qualifications}

The successful candidate will have the following basic qualifications:

\begin{itemize}
\item{\qualificationa}%
\item{\qualificationb}%
\item{\qualificationc}%
%\item{\qualificationd}%
\end{itemize}

\end{document}

这种 mwe 效率低下,而且毫无用处,原因显而易见:(1)使用定义不会减少代码的大小或复杂性(2)必须管理a, b,ETC。后缀。

以下伪代码将解决这两个问题

\documentclass{article}%

% BASIC QUALIFICATIONS

% define an array called \qualifications which has the elements:
% A degree
% Skill
% Common sense
% Enthusiasm

\begin{document}

% duties
\section*{Basic Qualifications}

The successful candidate will have the following basic qualifications:

\begin{itemize}
% for all elements in the array, wrap the value of the array element at index defined by the for loop counter with `\item{` and `}`
\end{itemize}

\end{document}

答案1

此类列表处理功能由etoolbox

在此处输入图片描述

\documentclass{article}

\usepackage{etoolbox}

% BASIC QUALIFICATIONS
\listadd\qualifications{A degree}%
\listadd\qualifications{Skill}%
\listadd\qualifications{Common sense}%
\listadd\qualifications{Enthusiasm}%

\begin{document}

% duties
\section*{Basic Qualifications}

The successful candidate will have the following basic qualifications:

\begin{itemize}
  \forlistloop{\item}{\qualifications}
\end{itemize}

\end{document}

相关内容