Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

My LaTeX code is:

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

Required Output is:

If arttype value is 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`.

If arttype value is 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 value is n number of times. I will print the each \art* values in each paragraph separately. How do control in LaTeX class file?

share|improve this question
    
On the surface, it appears you would like the output "5th" as a string. On the other hand, perhaps you mean to signify elements of an array, in which, for example, "5thArticle Title" is some arbitrary string associated with the 5th element of the array. Perhaps a clarification would help. And if the latter, how do you propose to make these array values available to the document? –  Steven B. Segletes Aug 28 '13 at 12:18
    
@Steven: I have updated the questions and 5th element is not a fixed value. In the latter i will print each array values in separate places. –  Balaji Aug 28 '13 at 12:24
add comment

2 Answers

up vote 2 down vote accepted

arrayjobx can help with such things. Perhaps this is what you're after:

enter image description here

\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}
share|improve this answer
    
This is easy work, but i have to store the value in variable and print to any other place (like \artcolor value should print each cross-link). No need to create any newcommand. How do achieve this? –  Balaji Aug 29 '13 at 6:25
    
@Balaji: I have no idea what you mean here, sorry. –  Werner Aug 29 '13 at 6:38
    
If I give \arttype{2} in LaTeX, the value of \artmisc{E2} only is like to display before \thebibliography. Not like to create any additional \newcommand or \def. –  Balaji Aug 29 '13 at 6:45
    
@Balaji: Could you include these details as part of your question, making it clear in the form of a minimal working example (MWE)? I still don't understand why with \arttype{2} you only mention \artmisc{E2} when your original post lists a host of possible outputs. Also, should I interpret that \arttype{2} should pass E2 as parameter to \artmisc and friends? –  Werner Aug 29 '13 at 7:30
    
I have updated the questions. I have need to print each \arttext, \artcolor separately in each paragraph. –  Balaji Aug 29 '13 at 7:55
show 7 more comments

Here is an answer if your data is in an external file (data.tex). If your data file is as follows:

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

then this 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}%
  }%
  \arrayij{mydata}{\therowindex}{1}%
}
\parindent 0in
\begin{document}
\readdef{data.tex}{\temp}
\copyrecords{mydata}
\underline{Data for record 5:}\\
\arttext{5}\\
\artshortname{5}\\
\artabbrtext{5}\\
\artcolor{5}\\
\artmisc{5}
\end{document}

will read through the records to produce the following:

enter image description here

share|improve this answer
2  
I think I have Nerds Gone Wild on one of my external drives :P –  percusse Aug 29 '13 at 15:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.