Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add localization controls to YAML template #9

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,35 @@ Although I didn't test it, you can probably use this on Windows, too. Both [Pand

## Available settings

- **`date`**: set a specific
- **`VAT`**: Your VAT rate.
- **`currency`**: Your currency code (USD, EUR...)
- **`commasep`**: Set to `true` to use a comma as decimal separator. This is for display purposes only—remember to always use a dot to set the prices in your YAML file.
- **`lang`**: Sets the main language through the `polyglossia` package. This is important for proper hyphenation and date format.
- **`language`**: Sets the main language through the `polyglossia` package. This is important for proper hyphenation and date format.
- **`seriffont`**: Used for the heading and the sender address. Hoefler Text is the default, but every font installed on your system should work out of the box (thanks, XeTeX!)
- **`sansfont`**: Used to render the recipient address, the table and the closing note. Defaults to Helvetica Neue.
- **`fontsize`**: Possible values here are 10pt, 11pt and 12pt.
- **`geometry`**: A string that sets the margins through `geometry`. Read [this](https://www.sharelatex.com/learn/Page_size_and_margins) to learn how this package works.
- **`closingnote`**: This gets printed after the table as a closing note. Use it to provide your bank details and a thank you message.
- **`letterhead`**: include custom letterhead in the PDF (see below).
- **`locale`**: configure strings and other locale related options. All strings default to their english variant
- **`commasep`**: Set to `true` to use a comma as decimal separator. This is for display purposes only—remember to always use a dot to set the prices in your YAML file.
- **`VAT`**: Set your local word for VAT here, e.g. MwSt. in geman
- **`price`**: Your local phrase for "price in"
- **`description`**: you get the idea ain't you? ;)
- **`subtotal`**: Netto
- **`total`**: Brutto
- **`itemPos`**: You can use `\phantom` to make shure the string is not displayed and not substituted by the english default value

## Custom letterhead

If you have already designed your own letterhead and want to use it with this template, including it should be easy enough. Set the `letterhead` option to `true` to activate the `wallpaper` package in the template. `wallpaper` will look for a file named `letterhead.pdf` in the project root folder and print it on the PDF before compiling the document. Change the fonts to match the ones in your letterhead, adjust the margins with `geometry` and you should be all set.







## Recommended readings

- [Typesetting Automation](http://mrzool.cc/writing/typesetting-automation/), my article about this project with in-depth instructions and some suggestions for an ideal workflow.
Expand Down
29 changes: 21 additions & 8 deletions details.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
invoice-nr: 2015-11-04
author: Max Mustermann
city: Musterstadt
date: \today # set custom date here
from:
- Musterstraße 37
- 12345 Musterstadt
Expand All @@ -24,22 +25,34 @@ service:
- description: The last service provided
price: 65.00

closingnote: |
closingnote: | # use \total to refer to the calculated sum
Please transfer the due amount to the following bank account within the next 14 days:
Mustermann GmbH
Kreditinstitut: Deutsche Postbank AG
IBAN: DE18 3601 0043 9999 9999 99
BIC: PBNKDEFF

Mustermann GmbH
Kreditinstitut: Deutsche Postbank AG
IBAN: DE18 3601 0043 9999 9999 99
BIC: PBNKDEFF

We really appreciate your business and look forward to future projects together.

Best regards,

signature:
# put path to an image of your signature here

# Invoice settings
currency: EUR
# commasep: true
lang: english

# Locale settings
language: english
locale:
commasep: true
VAT: MwSt.
price: Preis in
description: Beschreibung
itemPos: Nr.
subtotal: Netto
total: Brutto

# Typography and layout
seriffont: Hoefler Text
Expand Down
12 changes: 7 additions & 5 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
TEX = pandoc
src = template.tex details.yml
PANDOC = /usr/bin/env pandoc
TEMPLATE = template.tex
src = details.yml
out = output.pdf
FLAGS = --pdf-engine=xelatex

output.pdf : $(src)
$(TEX) $(filter-out $<,$^ ) -o $@ --template=$< $(FLAGS)
render : $(src)
$(PANDOC) -o $(out) --template=$(TEMPLATE) $(FLAGS) --standalone -- $(src)

.PHONY: clean
clean :
rm output.pdf
rm $(name)
73 changes: 48 additions & 25 deletions template.tex
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode

\documentclass[$fontsize$, a4paper]{article}

\documentclass[$if(fontsize)$$fontsize$,$endif$$if(lang)$$babel-lang$,$endif$$if(papersize)$$papersize$paper$endif$]{article}
% LAYOUT
%--------------------------------
\usepackage{geometry}
\usepackage{geometry}
\geometry{$geometry$}

% No page numbers
\pagenumbering{gobble}

% Left align
% Left aligngit
\usepackage[document]{ragged2e}

$if(letterhead)$
Expand All @@ -22,7 +21,7 @@

% TYPOGRAPHY
%--------------------------------
\usepackage{fontspec}
\usepackage{fontspec}
\usepackage{xunicode}
\usepackage{xltxtra}

Expand Down Expand Up @@ -61,12 +60,40 @@
\setlist[itemize]{leftmargin=0.5cm} % Reduce list left indent
\setlength{\tabcolsep}{9pt} % Larger gutter between columns

% allow including of signatures
\usepackage{graphicx}

% MACROS
\newcommand{\total}{\STtag{totalsum}}
% MACROS:Locale
$if(locale.commasep)$\STsetdecimalsep{,}$endif$ % Use comma as decimal separator
\newcommand{\localInvoice}
{$if(locale.invoice)$$locale.invoice$$else$Invoice$endif$}
\newcommand{\localDescription}
{$if(locale.description)$$locale.description$$else$Description$endif$}
\newcommand{\localItemPos}
{$if(locale.itemPos)$$locale.itemPos$$else$Pos.$endif$}
\newcommand{\localPriceIn}
{$if(locale.price)$$locale.price$$else$Price in$endif$}
\newcommand{\localSubtotal}
{$if(locale.subtotal)$$locale.subtotal$$else$Subtotal$endif$}
\newcommand{\localTotal}
{$if(locale.total)$$locale.total$$else$Total$endif$}
\newcommand{\localVAT}
{$if(locale.VAT)$$locale.VAT$$else$VAT$endif$}


% LANGUAGE
%--------------------------------
$if(lang)$
\usepackage{polyglossia}
\setmainlanguage{$lang$}
\setmainlanguage{$polyglossia-lang$}
\usepackage[
useregional,
$if(datetime2)$
$datetime2$
$endif$]{datetime2}
$if(datestyle)$
\DTMsetstyle{$datestyle$}
$endif$

% PDF SETUP
Expand All @@ -83,12 +110,6 @@
urlcolor=blue
}

% To display custom date
% \usepackage[nodayofweek]{datetime}
% \newdate{date}{01}{12}{1867}
% \date{\displaydate{date}}
% Use this instead of \today: % \displaydate{date}

% DOCUMENT
%--------------------------------
\begin{document}
Expand All @@ -109,33 +130,31 @@

\begin{flushright}
\small
$city$, \today
$city$, $if(date)$\date{$date$}$else$\Today$endif$
\end{flushright}

\vspace{1em}


\section*{\textsc{Invoice} \textsc{\#$invoice-nr$}}
\section*{\textsc{\localInvoice} \textsc{$invoice-nr$}}
\footnotesize
\newcounter{pos}
\setcounter{pos}{0}
\STautoround*{2} % Get spreadtab to always display the decimal part
$if(commasep)$\STsetdecimalsep{,}$endif$ % Use comma as decimal separator

\begin{spreadtab}{{tabular}[t t t]{lp{8.2cm}r}}
\hdashline[1pt/1pt]
@ \noalign{\vskip 2mm} \textbf{Pos.} & @ \textbf{Description} & @ \textbf{Prices in $currency$} \\ \hline
$for(service)$ @ \noalign{\vskip 2mm} \refstepcounter{pos} \thepos
& @ $service.description$
$if(service.details)$\newline \begin{itemize}
$for(service.details)$\scriptsize \item $service.details$
@ \noalign{\vskip 2mm} \textbf{\localItemPos} & @ \textbf{\localDescription} & @ \textbf{\localPriceIn~$currency$} \\ \hline
$for(service)$ @ \noalign{\vskip 2mm} \refstepcounter{pos} \thepos
& @ $service.description$
$if(service.details)$\newline \begin{itemize}
$for(service.details)$\scriptsize \item $service.details$
$endfor$ \end{itemize}
$endif$ & $service.price$\\$endfor$ \noalign{\vskip 2mm} \hline
$if(VAT)$
@ & @ \multicolumn{1}{r}{Subtotal:} & :={sum(c1:[0,-1])} \\ \hhline{~~-}
@ & @ \multicolumn{1}{r}{VAT $VAT$\%:} & $VAT$/100*[0,-1] \\ \hhline{~~-}
@ & @ \multicolumn{1}{r}{\localSubtotal:} & :={sum(c1:[0,-1])} \\ \hhline{~~-}
@ & @ \multicolumn{1}{r}{\localVAT $VAT$\%:} & $VAT$/100*[0,-1] \\ \hhline{~~-}
$endif$
@ & @ \multicolumn{1}{r}{\textbf{Total:}} & \textbf{:={$if(VAT)$[0,-1]+[0,-2]$else$sum(c1:[0,-1])$endif$}} \\ \hhline{~~-}
@ & @ \multicolumn{1}{r}{\textbf{\localTotal:}} & \textbf{:={$if(VAT)$[0,-1]+[0,-2]tag(totalsum)$else$sum(c1:[0,-1])tag(totalsum)$endif$}} \\ \hhline{~~-}
\end{spreadtab}


Expand All @@ -149,4 +168,8 @@ \section*{\textsc{Invoice} \textsc{\#$invoice-nr$}}

$author$

$for(signature)$
\includegraphics[width=3cm]{$signature$}
$endfor$

\end{document}