My problem, is to generate some .tex-file from within another .tex-file. The origin of problem is to extract some information from scientific paper, and create another .tex->.pdf-file with data about authors and so on.
My MWE now work with using \string, but if I want to create many lines in outputted .tex, it is easy to make a mistake. Is any simple solution?
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T2A,T1]{fontenc}
%\usepackage{filecontents}
\makeatletter
\def\macroPass#1{%
\if\relax\detokenize{#1}\relax
\else
\def\macroPrint{#1}
\fi
}
\makeatother
\begin{document}
\newwrite\regformfile
\newcommand\writeregformfile{%
\immediate\openout\regformfile=data.tex
\immediate\write\regformfile{
\string\documentclass{article}^^J
\string\begin{document}^^J
\string\begin{center} \string\bfseries^^J
\string\begin{tabular}{|l|l|}^^J
\string\hline^^J
Field& \unexpanded\expandafter{\macroPrint} \string\\ \string\hline^^J
\string\end{tabular}^^J
\string\end{center}^^J
\string\end{document}
}
}
\macroPass{To data.tex}
\writeregformfile
\end{document}
MWE with folecontents, which is work incorrect.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T2A,T1]{fontenc}
%\usepackage{filecontents}
\makeatletter
\def\macroPass#1{%
\if\relax\detokenize{#1}\relax
\else
\def\macroPrint{#1}
\fi
}
\makeatother
\begin{filecontents*}{data.tex}
\documentclass{article}
\begin{document}
\begin{center}\bfseries
\begin{tabular}{|l|l|}
\hline
Field& \macroPrint \\ \hline
\end{tabular}
\end{center}
\end{document}
\end{filecontents*}
\begin{document}
\macroPass{To data.tex}
\end{document}
^^Jmakes a newline) – David Carlisle May 27 '16 at 15:35\unexpanded{....}around the whole thing. – David Carlisle May 27 '16 at 15:40filecontents(which doesn't need a package) the\macroPasscommand you define doesn't seem to be related in any way to the file writing? – David Carlisle May 27 '16 at 15:42{data.tex}should be an argument to filecontents not to\documentclassthen either filecontents needs to be at the start of the file, or use the filecontens package version – David Carlisle May 27 '16 at 16:14\macroPass{To data.tex}to do? currently it just defines an unused macro, after the data.tex file is written out. – David Carlisle May 27 '16 at 16:15