<commit_before>package webconform

import (
	"io/ioutil"
	"os"
	"os/exec"
	"path"
	"strings"
	"text/template"
)

const Template = "conform.tex.tmpl"

var funcMap = template.FuncMap{
	"divide": Divide,
}

func Divide(a, b float64) float64 { return a / b }

// Create parses the templates and runs pdflatex on the resulting tex file. It returns generated PDF.
func (c *Conform) Create(tmplDir, tmpl string) ([]byte, error) {
	c.escapeTex()
	err := c.FillOut()
	if err != nil {
		return nil, err
	}

	dst, err := ioutil.TempDir("/tmp", "pdflatex")
	if err != nil {
		return nil, err
	}
	defer os.RemoveAll(dst)

	sources, err := TeXFiles(tmplDir)
	if err != nil {
		return nil, err
	}
	for _, src := range sources {
		basename := path.Base(src)
		if err := os.Symlink(src, path.Join(dst, basename)); err != nil {
			return nil, err
		}
	}

	conformTex := path.Join(dst, "conform.tex")

	// We use @@ in the tmpl, because {{ is in heavy use by TeX.<commit_msg>Fix<commit_after>package webconform

import (
	"io/ioutil"
	"os"
	"os/exec"
	"path"
	"strings"
	"text/template"
)

const Template = "conform.tex.tmpl"

var funcMap = template.FuncMap{
	"divide": Divide,
}

func Divide(a float64, b int) float64 { return a / float64(b) }

// Create parses the templates and runs pdflatex on the resulting tex file. It returns generated PDF.
func (c *Conform) Create(tmplDir, tmpl string) ([]byte, error) {
	c.escapeTex()
	err := c.FillOut()
	if err != nil {
		return nil, err
	}

	dst, err := ioutil.TempDir("/tmp", "pdflatex")
	if err != nil {
		return nil, err
	}
	defer os.RemoveAll(dst)

	sources, err := TeXFiles(tmplDir)
	if err != nil {
		return nil, err
	}
	for _, src := range sources {
		basename := path.Base(src)
		if err := os.Symlink(src, path.Join(dst, basename)); err != nil {
			return nil, err
		}
	}

	conformTex := path.Join(dst, "conform.tex")

	// We use @@ in the tmpl, because {{ is in heavy use by TeX.
{'fraction_non_alphanumeric': 0.14830287206266318, 'fraction_numerical': 0.005221932114882507, 'mean_word_length': 3.4558139534883723, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4847769', 'n_tokens_mistral': 770, 'n_tokens_neox': 738, 'n_words': 220}