Templates

by Armaghan Saqib, Thursday, December 15, 2022, 01:58 (471 days ago)

Templates are used in sql-ledger to customize invoices, orders print formats allowing users to use different set of templates for different languages.

There are 4 type of templates:

html
latex
text
XML

Templates processing workflow:

When any documents need to be printed, Perl code retrieves data from database, stores it in $form variables and then calls $form->parse_template to process that particular template.

Within the template, template variables are replaced with the data in $form variables and a temporary latex file is generated (for latex templates) and then converted to pdf.

Template variables are of the format <%variablename%>

So if you have $form->{firstname} = 'Armaghan Saqib' and then use <%firstname%> in the template, 'Armaghan Saqib' will replace the variable in the processed template file.

Latex beginner guide

by Armaghan Saqib, Friday, December 16, 2022, 01:48 (470 days ago) @ Armaghan Saqib
edited by Armaghan Saqib, Friday, December 16, 2022, 02:01

Hello world in latex

Create a text file (hello.tex) in your home folder with following text:

\documentclass[a4paper,11pt]{article}
\begin{document}
Hello world!
\end{document}

Compile this tex file into dvi file and use xdvi to view it:

latex hello.tex
xdvi hello.dvi


You can also convert it to pdf:
pdflatex hello.tex
xpdf hello.pdf

Structure of latex document

  • Latex commands start with a backslash (\).

  • Parameters can follow the command.

  • Optional parameters are enclosed in [ ] while mandatory ones are enclosed in {
    }.

  • { } can also be used to terminated a command mixed within some text (to
    make it easier for the compiler to understand the command).

  • Special characters in latex (#, $, %, ^, &, _, {, }, ~) are escaped with \ except for the \ character itself which is used to break a line.

  • To use literal backslash (\) you can use the special command $\backslash$.

  • Single line comments start with % while multi-line comments can be enclosed between \begin{comment} and \end{comment} structure.

  • Every latex document starts with \documentclass with parameters ([a4paper,11pt]{article})
    following it.

Exercises:

1. View latex templates in sql-ledger
2. View latex templates in a text editor like vim to see the color coded syntax which will help you understand the latex template structure in a better way.

RSS Feed of thread