go(report): make report creation just work™
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-07-18 01:50:40 +02:00
parent 9435f81fa2
commit 5eaeb9c692
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
5 changed files with 395 additions and 58 deletions

324
.gitignore vendored
View File

@ -7,6 +7,11 @@ math-optim
# output dir for generated plot pics/tex files
out
# generated files in the root of the project
report.pdf
report.tex
meta.sty
.vimrc
# drone starlark command used for "test-conversion" to yaml (by default)
@ -19,3 +24,322 @@ out
# ignore image outputs by default, requiring explicit overrides
*.png
*.jp?g
# the following part was created by https://www.toptal.com/developers/gitignore/api/tex
### TeX ###
## Core latex/pdflatex auxiliary files:
*.aux
*.lof
*.log
*.lot
*.fls
*.out
*.toc
*.fmt
*.fot
*.cb
*.cb2
.*.lb
## Intermediate documents:
*.dvi
*.xdv
*-converted-to.*
# these rules might exclude image files for figures etc.
# *.ps
# *.eps
# *.pdf
## Generated if empty string is given at "Please type another file name for output:"
.pdf
## Bibliography auxiliary files (bibtex/biblatex/biber):
*.bbl
*.bcf
*.blg
*-blx.aux
*-blx.bib
*.run.xml
## Build tool auxiliary files:
*.fdb_latexmk
*.synctex
*.synctex(busy)
*.synctex.gz
*.synctex.gz(busy)
*.pdfsync
## Build tool directories for auxiliary files
# latexrun
latex.out/
## Auxiliary and intermediate files from other packages:
# algorithms
*.alg
*.loa
# achemso
acs-*.bib
# amsthm
*.thm
# beamer
*.nav
*.pre
*.snm
*.vrb
# changes
*.soc
# comment
*.cut
# cprotect
*.cpt
# elsarticle (documentclass of Elsevier journals)
*.spl
# endnotes
*.ent
# fixme
*.lox
# feynmf/feynmp
*.mf
*.mp
*.t[1-9]
*.t[1-9][0-9]
*.tfm
#(r)(e)ledmac/(r)(e)ledpar
*.end
*.?end
*.[1-9]
*.[1-9][0-9]
*.[1-9][0-9][0-9]
*.[1-9]R
*.[1-9][0-9]R
*.[1-9][0-9][0-9]R
*.eledsec[1-9]
*.eledsec[1-9]R
*.eledsec[1-9][0-9]
*.eledsec[1-9][0-9]R
*.eledsec[1-9][0-9][0-9]
*.eledsec[1-9][0-9][0-9]R
# glossaries
*.acn
*.acr
*.glg
*.glo
*.gls
*.glsdefs
*.lzo
*.lzs
*.slg
*.slo
*.sls
# uncomment this for glossaries-extra (will ignore makeindex's style files!)
# *.ist
# gnuplot
*.gnuplot
*.table
# gnuplottex
*-gnuplottex-*
# gregoriotex
*.gaux
*.glog
*.gtex
# htlatex
*.4ct
*.4tc
*.idv
*.lg
*.trc
*.xref
# hypdoc
*.hd
# hyperref
*.brf
# knitr
*-concordance.tex
# TODO Uncomment the next line if you use knitr and want to ignore its generated tikz files
# *.tikz
*-tikzDictionary
# listings
*.lol
# luatexja-ruby
*.ltjruby
# makeidx
*.idx
*.ilg
*.ind
# minitoc
*.maf
*.mlf
*.mlt
*.mtc[0-9]*
*.slf[0-9]*
*.slt[0-9]*
*.stc[0-9]*
# minted
_minted*
*.pyg
# morewrites
*.mw
# newpax
*.newpax
# nomencl
*.nlg
*.nlo
*.nls
# pax
*.pax
# pdfpcnotes
*.pdfpc
# sagetex
*.sagetex.sage
*.sagetex.py
*.sagetex.scmd
# scrwfile
*.wrt
# svg
svg-inkscape/
# sympy
*.sout
*.sympy
sympy-plots-for-*.tex/
# pdfcomment
*.upa
*.upb
# pythontex
*.pytxcode
pythontex-files-*/
# tcolorbox
*.listing
# thmtools
*.loe
# TikZ & PGF
*.dpth
*.md5
*.auxlock
# titletoc
*.ptc
# todonotes
*.tdo
# vhistory
*.hst
*.ver
# easy-todo
*.lod
# xcolor
*.xcp
# xmpincl
*.xmpi
# xindy
*.xdy
# xypic precompiled matrices and outlines
*.xyc
*.xyd
# endfloat
*.ttt
*.fff
# Latexian
TSWLatexianTemp*
## Editors:
# WinEdt
*.bak
*.sav
# Texpad
.texpadtmp
# LyX
*.lyx~
# Kile
*.backup
# gummi
.*.swp
# KBibTeX
*~[0-9]*
# TeXnicCenter
*.tps
# auto folder when using emacs and auctex
./auto/*
*.el
# expex forward references with \gathertags
*-tags.tex
# standalone packages
*.sta
# Makeindex log files
*.lpz
# xwatermark package
*.xwm
# REVTeX puts footnotes in the bibliography by default, unless the nofootinbib
# option is specified. Footnotes are the stored in a file with suffix Notes.bib.
# Uncomment the next line to have this generated file ignored.
#*Notes.bib
### TeX Patch ###
# LIPIcs / OASIcs
*.vtc
# glossaries
*.glstex
# End of https://www.toptal.com/developers/gitignore/api/tex

View File

@ -32,7 +32,8 @@ func main() {
report.SaveTexAllPics()
report.SaveTexAllTables()
report.Print()
report.SaveAndPrint()
log.Println("looks like we're done")
log.Println("run an equivalent of `pdflatex -clean -shell-escape -interaction=nonstopmode ./report.tex` to get a pdf")
}

View File

@ -1,48 +0,0 @@
// Copyright 2022 wanderer <a_mirre at utb dot cz>
// SPDX-License-Identifier: GPL-3.0-or-later
//go:build ignore
// +build ignore
package main
import (
_ "embed"
"log"
"os"
"text/template"
"time"
)
var (
//go:embed report_base.tex
reportBase []byte
//go:embed report.tmpl
tmplReportFile []byte
)
func main() {
fName := "../out/tex/report.tex"
f, err := os.Create(fName)
if err != nil {
log.Fatal(err)
}
defer f.Close()
tmplReport := template.New("report")
tmplReport = template.Must(tmplReport.Parse(string(tmplReportFile)))
err = tmplReport.Execute(f, struct {
ReportBase string
Timestamp time.Time
}{
ReportBase: string(reportBase),
Timestamp: time.Now(),
})
if err != nil {
log.Println(err)
}
}

View File

@ -3,13 +3,14 @@
package report
//go:generate go run gen.go
import (
_ "embed"
"fmt"
"io"
"log"
"os"
"text/template"
"time"
)
const (
@ -18,6 +19,15 @@
picsDir = "pics/"
)
var (
//go:embed report_base.tex
reportBase []byte
//go:embed meta.sty
metaSty []byte
//go:embed report.tmpl
tmplReportFile []byte
)
// GetPicsDirPrefix returns the path to the folder meant for tex files.
func GetTexDir() string {
return outPrefix + texDir
@ -28,12 +38,62 @@ func GetPicsDir() string {
return outPrefix + picsDir
}
// Print prints stats in a report format.
func Print() {
fmt.Fprint(os.Stderr, "\n* printing the report...\n\n")
func emitReportTex(fname string) error {
f, err := os.Create(fname)
if err != nil {
log.Fatal(err)
}
// when run from the repo root
fname := GetTexDir() + "report.tex"
defer f.Close()
tmplReport := template.New("report")
tmplReport = template.Must(tmplReport.Parse(string(tmplReportFile)))
err = tmplReport.Execute(f, struct {
ReportBase string
Timestamp time.Time
}{
ReportBase: string(reportBase),
Timestamp: time.Now(),
})
if err != nil {
log.Println(err)
}
return err
}
func saveMetaSty() error {
// save meta.sty
fmeta, err := os.Create("meta.sty")
if err != nil {
log.Fatal(err)
}
defer fmeta.Close()
_, err = fmeta.Write(metaSty)
return err
}
// SaveAndPrint emits the tex files necessary to compile the report in full
// (report.tex, meta.sty) and prints the report.tex file to console.
func SaveAndPrint() {
fname := "report.tex"
err := emitReportTex(fname)
if err != nil {
log.Fatal(err)
}
err = saveMetaSty()
if err != nil {
log.Fatal(err)
}
fmt.Fprint(os.Stderr, "\n* printing the report...\n\n")
fh, err := os.Open(fname)
if err != nil {

View File

@ -36,10 +36,10 @@
\tableofcontents
\pagebreak
\input{allpics}
\input{out/tex/allpics}
\newpage
\input{alltables}
\input{out/tex/alltables}
\newpage
\listoffigures