Skip to content
This repository has been archived by the owner on Aug 25, 2023. It is now read-only.

trumpi/texlate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Texlate

Texlate is a command line application that generates a LaTeX document by applying values provided by the user to a template.

The provided values are collected from the command line using an interactive series of prompts.

Installing

The easiest way to install Texlate is via Homebrew

On systems with Homebrew:

brew tap SirRippovMaple/tap
brew install texlate

On systems with Go 1.16:

go get SirRippovMaple/texlate
go build

Alternatively, you can download pre-compiled binaries for the latest release in the GitHub Releases.

Usage

Texlate requires an existing template to run. The examples directory contains some example templates, but typically you will write your own.

To run texlate with brand new values, enter texlate create <template> from your terminal.

texlate create <template>

Template from scratch

Optional flags:
  -h, --help     Show context-sensitive help (also try --help-long and --help-man).
  -V, --version  Show application version.

Args:
  <template>  source template file

texlate create will write a tex and json file. It will also write a pdf file by invoking pdflatex.

To run texlate and pre-fill existing values, enter texlate update <jsonfile>, where <jsonfile> is a json file generated by texlate create.

texlate update <jsonfile>

Update a document from an existing values file

Optional flags:
  -h, --help     Show context-sensitive help (also try --help-long and --help-man).
  -V, --version  Show application version.

Args:
  <jsonfile>  previous answers

Every template should include a call to SetOutputFilename. This function takes one parameter, which is the file name of the output file. The output filename should not contain an extension because texlate will append .tex, .json and .pdf to the this value for each of the output files that it generates. The output file name may contain path components and texlate will attempt to create any paths that don't already exist.

If a template does not make any call to SetOutputFilename, then the resulting tex script will be written to stdout and pdf generation will not be attempted.

Writing templates

A template for texlate is a LaTeX formatted file with portions delimited for the Goland templating engine.

Texlate uses the Go templating engine with custom delimiters. Instead of the {{ delimiter, texlate uses \begin{template} and instead of }}, texlate uses \end{template}. Using the default {{ delimiter creates a problem with the LaTeX file format because starting a template directly after a { token confuses the Go templating engine.

Texlate provides several helper functions to obtain values interactively:

PromptBool(key string, prompt string) string
PromptString(key string, prompt string) string
PromptSelect(key string, prompt string, options ...string) string

The first parameter of each function is a unique key that identifies the value in the output json file. The second parameter is a prompt shown to the user. PromptSelect takes additional parameters that are the valid values. These are shown to the user.

\begin{document}
\begin{template}
$stringVariable := .PromptString "theString" "Enter any string: " 
-\end{template}

The string you entered (\begin{template}$stringVariable\end{template}) is now stored in a variable.

\begin{template} if .PromptBool "firstBool" "Do you want to expand the first section ---> " -\end{template}
This text appears if you confirm the first conditional.

\begin{template} if .PromptBool "secondBool" "Do you want to expand the nested conditional ---> " -\end{template}
This text only appears if you answered yes to both of the previous questions.
\begin{template}end -\end{template}
\being{template}end -\end{template}
\end{document}

Contributing

If you have an idea for texlate, use this link. Since texlate is pre-release, many of the decisions that we've taken are subject to change and better suggestions for these are welcome to be logged as ideas. This includes the decision about delimiters, the behavior when SetOutputFilename is not called, improvements to documentation & messages, good example templates, etc.

If you want to report a bug, use this link.

If you want to increase the chances of your idea or fix being incorporated, please submit a pull request.

Credit

This work is based off the work of Jake Warren.

About

Texlate is a command line application that generates a LaTeX document by applying values provided by the user to a template.

Topics

Resources

License

Stars

Watchers

Forks

Languages