A Golang package to compile a tex to a PDF by running the xelatex command
-
Install TexLive
tex2pdf calls
xelatex
command which comes with installation of TexLive. Download and install TexLive("scheme-full" is recommended). -
Install minted pacakge and pygments
minted is used for code highlighting. Our test case includes compiling
.tex
file which uses minted for code highlighting("src/02-usage.tex").
package main
import (
"fmt"
"log"
"path/filepath"
"github.com/northbright/tex2pdf"
)
func main() {
// Open DEBUG mode if need.
//tex2pdf.DebugMode = true
texFile := "src/my_book.tex"
// Compile a tex file to PDF.
pdf, err := tex2pdf.Tex2PDF(texFile)
if err != nil {
log.Printf("Tex2PDF() error: %v", err)
return
}
fmt.Printf("Tex2PDF OK, output pdf: %v\n", filepath.Base(pdf))
// Output:
//Tex2PDF OK, output pdf: my_book.pdf
}