In this question here on the TeX-forum, I asked for a method to store variables in a convenient way, so that non-techies are not scared off to work with LaTeX. To bring this up to a new level, I'd like to define the complete structure of the document, in this case an invoice, in the .cls file, including text output.
This is not really possible, as you are not allowed to print content before the \begin{document} command.
What I'd like to have is a two documents folder setup. The invoice.clsdocument class file, preformatting everything and the main.tex file in which the end user can enter the variables as shown in the previous question and set up the bill.
For the bill I defined a newenvironment with some custom commands and counters, so that the total amount is calculated by LaTeX and printed on the page.
Ideally the main.tex should only contain these two things:
\documentclass{invoice}
\begin{document}
\StoreInvoiceData{%
%% %%%%%%
%% Sender
%% %%%%%%
Tagline = {Hello World},
FirstName = {Victor K.},
LastName = {Driscoll},
Street = {1616 Hill Croft Farm Road},
Zip = {95932},
Town = {Colusa},
Country = {USA},
IBAN = {YY24KIHB12476423125915947930915268},
SWIFT = {ANTSUB4L},
%% %%%%%%%%
%% Receiver
%% %%%%%%%%
ClientFirstName = {John},
ClientLastName = {Doe},
ClientStreet = {123 Main St},
ClientZip = {43221},
ClientTown = {Anytown},
ClientCountry = {USA}
}
\begin{invoicetable}
%% %%%%%%%
%% Hosting
%% %%%%%%%
\feetype{Hosting Expenses}
\unitrow{Test 1}{1}{10} % \unitrow{Name}{Quantity}{Item price}
\unitrow{Test 2}{1}{15}
\unitrow{Test 3}{1}{20}
\subtotal
%% %%%%%%%%%%%%
%% Maintainance
%% %%%%%%%%%%%%
\feetype{Maintenance Fees}
\unitrow{Test 4}{2}{15}
\unitrow{Test 5}{1}{20}
\unitrow{Test 6}{5}{25}
\unitrow{Test 7}{1}{30}
\subtotal
\end{invoicetable}
\end{document}
The invoice.cls should handle all the rest. If no values are entered in the \StoreInvoiceData-list, blank fields should be printed. The class should automatically print the header (a TikZ rectangle with nodes that include the name an the tagline), the address field (also a TikZ rectangle placed at the correct coordinates to match the window in an envelope) and so on.
At the moment this is all done by \newcommands which are then called in the main.tex, but as I said, I want tho keep that file as clean as possible and I'm sure that there is a possibility to define the complete layout in a LaTeX class.
If something is not clear, please feel free to ask.
Thanks for your help, I really appreciate it!

datatooland have the users simply enter data in Excel. – Alan Munn Aug 04 '17 at 17:04main.texfile. Theinvoice.clsis ready to use and should not be modified by the end user. That's pretty easy I'd say, isn't it? – Sam Aug 04 '17 at 18:04\TagLineFormatetc. for each of your invoice data fields. This can be 'looped', but you would still have to provide some default formats – Aug 04 '17 at 19:01\documentclass{invoice}\InputFile{myfile.csv}\begin{document}\printinvoice\end{document}(which could itself be scripted if you wanted.) (Where\InputFileand\printinvoiceare the only user commands of the class.) Everything else is taken from the CSV file usingdatatooland marked up and formatted by the class. – Alan Munn Aug 04 '17 at 19:15.csvfile only includes data, so it replaces the list of key/value pairs. As I said in my question, I don't know how to format the output without beginning the document. All I know is how to format things when defining a new environment or a newcommand which is then called in themain.texBut you don't use any of these methods, and I also don't want to use any of these, so how can I format the output in the class file? – Sam Aug 04 '17 at 19:46\printinvoicemeant to be such a\newcommandwhich sets everything up? – Sam Aug 04 '17 at 19:53textmergcan be used in the same way. I use a spreadsheet to hold student data and calculate marks. At the end of the module, I save one sheet of this as a.csvfile, feed that into a simple wrapper and a custom class produces a module assessment form for each student. All the formatting is done by the class. All the calculating is done by Calc. And it is much easier to see and assess the data during the semester in spreadsheet format. (Actually, I also pre-process the.csvinto a.datusing a bash script, but this is not really important.) – cfr Aug 04 '17 at 22:08