package latex import ( "log" "os" "text/template" "git.dekart811.net/icedream/workreportmgr/export/latex/stringutil" "git.dekart811.net/icedream/workreportmgr/project" "github.com/jinzhu/now" "github.com/nicksnyder/go-i18n/i18n" ) const dateFormat = "02.01.2006" // TODO - localize! var exportTemplate = template.Must(template. New("latex_export"). Funcs(template.FuncMap{ "T": i18n.IdentityTfunc, "escape": stringutil.TexEscape, "add": func(a, b int) int { return a + b }, "beginofweek": func(date project.Date) project.Date { return project.Date{now.New(date.Time).BeginningOfWeek()} }, "endofweek": func(date project.Date) project.Date { return project.Date{now.New(date.Time).EndOfWeek()} }, }). Delims("<", ">"). Parse(`% !TeX <- with .TexMarker.Program> program = <.> \documentclass[11pt,a4paper,oneside]{article} \usepackage{fancyhdr} \usepackage{tabularx} \usepackage[left=2cm,right=2cm,top=2cm,bottom=6cm,includeheadfoot]{geometry} \usepackage{csquotes} \usepackage{fontspec} \usepackage{ifluatex} \ifluatex \else \usepackage[utf8]{inputenc} \fi \pagestyle{fancy} \fancyhf{} \setlength{\headheight}{2cm} \newcommand{\Name}{<.Project.Name>} \newcommand{\Department}{<.Project.Department>} \newcommand{\wrSigningField}[0]{ \begin{tabularx}{\textwidth}{| X | X | X |} \hline & & \\[2cm] \hline \end{tabularx} } \newenvironment{weeklyreport}{ }{ \fancyfoot[C]{\wrSigningField} } \newcommand{\preweeklyreporthead}[3]{} \newcommand{\weeklyreporthead}[3]{ \preweeklyreporthead{#1}{#2}{#3} \fancyhead[R]{ \begin{tabularx}{8cm}{rl} \textbf{}: & \Name \\ \textbf{}: & \Department \\ \textbf{}: & #2 - #3 \\ \end{tabularx} } \fancyfoot{} \newpage \setcounter{section}{#1} \setcounter{subsection}{0} \section*{} \addcontentsline{toc}{section}{} } \newcommand{\weeklyreportsection}[1]{ \subsection*{#1} } \input{<.>} \begin{document} \tableofcontents \begin{weeklyreport} \weeklyreporthead{}{}{} \weeklyreportsection{} \begin{itemize} \item <. | escape> \end{itemize} \weeklyreportsection{} <$week.WorkActivityDetails | escape> \weeklyreportsection{} \begin{itemize} \item{ <- .Subject | escape -> <- with .Topics ->: <- if ne $index 0 ->, <- $topic | escape -> <- end -> <- end -> } \end{itemize} \end{weeklyreport} \end{document} `)) func initTemplate() { log.Println("Initializing template for LaTeX export...") var err error defer func() { if err != nil { log.Fatal("Failed at initializing template.", err) os.Exit(0xFF) } }() }