输入单个值,存储5个不同的值

输入单个值,存储5个不同的值

我的 LaTeX 代码是:

\documentclass{thesis}
\begin{document}
\arttype{5}
\end{document}

所需输出为:

如果arttype值为5

`5thArticle Title-tnins` is need to store in \newcommand `\arttext`.
`5thArticle Short Title-tnins` is need to store in newcommand `\artshortname`.
`5thArticle Sub-Title-tnins` is need to store in newcommand `\artabbrtext`.
`5thArticle Color X-tnins` is need to store in newcommand `\artcolor`.
`5thArticle Misc. Value-tnins` is need to store in newcommand `\artmisc`.

如果arttype值为8

`8thArticle Title-toins` is need to store in \newcommand `\arttext`.
`8thArticle Short Title-toins` is need to store in newcommand `\artshortname`.
`8thArticle Sub-Title-toins` is need to store in newcommand `\artabbrtext`.
`8thArticle Color X-toins` is need to store in newcommand `\artcolor`.
`8thArticle Misc. Value-toins` is need to store in newcommand `\artmisc`.

arttype值是n次数。我将\art*分别打印每个段落中的每个值。如何在 LaTeX 类文件中进行控制?

答案1

arrayjobx可以帮助解决这些问题。也许这就是你想要的:

在此处输入图片描述

\documentclass{article}
\usepackage{arrayjobx}% http://ctan.org/pkg/arrayjobx
\makeatletter
\newarray\arttext@aux\readarray{arttext@aux}{A1 & A2 & A3 & A4 & A5 & A6}
\newarray\artshortname@aux\readarray{artshortname@aux}{B1 & B2 & B3 & B4 & B5 & B6}
\newarray\artabbrtext@aux\readarray{artabbrtext@aux}{C1 & C2 & C3 & C4 & C5 & C6}
\newarray\artcolor@aux\readarray{artcolor@aux}{D1 & D2 & D3 & D4 & D5 & D6}
\newarray\artmisc@aux\readarray{artmisc@aux}{E1 & E2 & E3 & E4 & E5 & E6}
\newcommand{\arttype}[1]{% \arttype{<num>}
  \def\arttext{\arrayx{arttext@aux}(#1)}%
  \def\artshortname{\arrayx{artshortname@aux}(#1)}%
  \def\artabbrtext{\arrayx{artabbrtext@aux}(#1)}%
  \def\artcolor{\arracyx{artcolor@aux}(#1)}%
  \def\artmisc{\arrayx{artmisc@aux}(#1)}%
}
\makeatother
\begin{document}
\arttype{5}\arttext\ \artmisc

\arttype{2}\arttext\ \artmisc
\end{document}

答案2

如果您的数据位于外部文件 (data.tex) 中,则答案如下。如果您的数据文件如下:

article 1 title
article 1 short title
article 1 sub-title
article 1 color
article 1 misc value

article 2 title
article 2 short title
article 2 sub-title
article 2 color
article 2 misc value

article 3 title
article 3 short title
article 3 sub-title
article 3 color
article 3 misc value

article 4 title
article 4 short title
article 4 sub-title
article 4 color
article 4 misc value

Memoirs of a LaTeXer
Mem. LaTeXer
Nerds Gone Wild
cyan
non-fiction

然后是这个 MWE:

\documentclass{article}
\usepackage{readarray}
\newcounter{index}
\newcounter{rowindex}
\newcommand\arttext[1]     {\artloop{#1}{1}}
\newcommand\artshortname[1]{\artloop{#1}{2}}
\newcommand\artabbrtext[1] {\artloop{#1}{3}}
\newcommand\artcolor[1]    {\artloop{#1}{4}}
\newcommand\artmisc[1]     {\artloop{#1}{5}}
\newcommand\artloop[2]{%
  \setcounter{rowindex}{#2}
  \setcounter{index}{1}
  \whiledo{\theindex<#1}{%
    \stepcounter{index}%
    \addtocounter{rowindex}{6}%
  }%
  \mydata[\therowindex]%
}
\parindent 0in
\begin{document}
\readrecordarray{data.tex}\mydata
\underline{Data for record 5:}\\
\arttext{5}\\
\artshortname{5}\\
\artabbrtext{5}\\
\artcolor{5}\\
\artmisc{5}
\end{document}

将阅读记录并得出以下结论:

在此处输入图片描述

相关内容