0

I create a table with 2 foreach-loops. Now I would like to have that as a textfile too.

But there are some if-decision. How to use newwrite correctly here?

textfile

\documentclass[]{article}
\usepackage{tikz}
\begin{document}
\def\xHead{A,I,U,E,O}
\def\yHead{xx, K,S,T,N,H,M,Y,R,W}

\section{In the Document - good}
% Headrow
yy, --A, --I, --U, --E, --O, N

\foreach[count=\row] \y  in \yHead{%
\ifnum\row=1 \y, \else \y-- \fi%
\ifnum\row=1 \xHead, N  \else
\foreach \x in \xHead{%
 \y\x, }  nn \fi
\par}

\section{As writeout - bad}
\newwrite\kanaoutfile
\immediate\openout\kanaoutfile=KanaData.txt%
% Headrow
\immediate\write\kanaoutfile{yy, --A, --I, --U, --E, --O, N}

\foreach[count=\row] \y  in \yHead{%
\immediate\write\kanaoutfile{\ifnum\row=1 \y, \else \y-- \fi}%
\ifnum\row=1 \immediate\write\kanaoutfile{\xHead, N} \else%
\foreach \x in \xHead{%
\immediate\write\kanaoutfile{\y\x,} nn }   \fi%
\par}
\immediate\closeout\kanaoutfile

\subsection{Test}
\input{KanaData.txt}
\end{document}
0

With pgfmath:

enter image description here

\documentclass[]{article}
\usepackage{tikz}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}
\begin{document}
\section{In the Document and as outfile - good}

\newwrite\kanaoutfile
\immediate\openout\kanaoutfile=KanaData.txt%
\newcommand{\row}{}% reserv Name
\foreach[count=\y from 0] \Y  in {{}, {}, K,S,T,N,H,M,Y,R,W}{%%%
\let\row=\empty% create List
\foreach[count=\x from 0] \X  in {{}, A,I,U,E,O,N}{%%
 \pgfmathparse{
 \y==0 ?  (\x==0 ? "yy" : (\x==6 ? "\X" : "--\X"))  : 
 (\y==1 ? (\x==0 ? "ee" : "\X") : (\x==0 ?  "\Y--" : 
 (\x==6 ? "nn" : "\Y\X")))}% 
  \ifx\empty\row{} \xdef\row{\pgfmathresult}%
  \else \xdef\row{\row,\pgfmathresult}%
  \fi
}%%
\noindent\row \\
\immediate\write\kanaoutfile{\row}
}%%5
\immediate\closeout\kanaoutfile

\subsection{Test}
%Show: \row
%\input{KanaData.txt}
\pgfplotstabletypeset[col sep=comma, string type]{KanaData.txt}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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