github.com/raphaelreyna/latte@v0.11.2-0.20220317193248-98e2fcef4eef/internal/job/options.go (about)

     1  package job
     2  
     3  import "os/exec"
     4  
     5  // Compiler represents the various compilers that are available
     6  type Compiler string
     7  
     8  func (c Compiler) IsValid() bool {
     9  	return c == CC_PDFLatex || c == CC_Latexmk
    10  }
    11  
    12  var (
    13  	CC_PDFLatex Compiler = "pdflatex"
    14  	CC_Latexmk  Compiler = "latexmk"
    15  	CC_Default  Compiler = CC_Latexmk
    16  )
    17  
    18  // Check if the system has Latemk installed, if so then make it the default
    19  func init() {
    20  	cmd := exec.Command("which", "latexmk")
    21  	_, err := cmd.CombinedOutput()
    22  	if err != nil {
    23  		CC_Default = CC_PDFLatex
    24  	} else {
    25  		CC_Default = CC_Latexmk
    26  	}
    27  }
    28  
    29  // MissingKeyOpt controls how missing keys are handled when filling in a template
    30  type MissingKeyOpt string
    31  
    32  var (
    33  	// MK_Error will cause an error if details is missing a key used in the template
    34  	MK_Error MissingKeyOpt = "error"
    35  	// MK_Zero will cause values whose keys are missing from details to be replace with a zero value.
    36  	MK_Zero MissingKeyOpt = "zero"
    37  	// MK_Nothing will cause missing keys to be ignored.
    38  	MK_Nothing MissingKeyOpt = "nothing"
    39  )
    40  
    41  func (mko MissingKeyOpt) IsValid() bool {
    42  	return mko == MK_Error || mko == MK_Zero || mko == MK_Nothing
    43  }
    44  
    45  func (mko MissingKeyOpt) Val() string {
    46  	switch mko {
    47  	case "":
    48  		fallthrough
    49  	case MK_Nothing:
    50  		return "default"
    51  	default:
    52  		return string(mko)
    53  	}
    54  }
    55  
    56  // Delimiters holds the left and right delimiters for a template
    57  type Delimiters struct {
    58  	Left  string
    59  	Right string
    60  }
    61  
    62  var DefaultDelimiters Delimiters = Delimiters{
    63  	Left:  "#!",
    64  	Right: "!#",
    65  }
    66  
    67  var BadDefaultDelimiters Delimiters = Delimiters{
    68  	Left:  "{{",
    69  	Right: "}}",
    70  }
    71  
    72  var EmptyDelimiters Delimiters = Delimiters{
    73  	Left:  "",
    74  	Right: "",
    75  }
    76  
    77  // Options holds the user settable options for a compilation job
    78  type Options struct {
    79  	// CC is the LaTeX compiler to use
    80  	CC Compiler
    81  	// N controls the number of compilations/passes.
    82  	N uint
    83  	// OnMissingKey controls how missing keys are handled when filling in the template
    84  	OnMissingKey MissingKeyOpt
    85  	// Delims holds the left and right delimiters to use for the template
    86  	Delims Delimiters
    87  }
    88  
    89  var DefaultOptions Options = Options{
    90  	CC:           CC_Default,
    91  	N:            1,
    92  	OnMissingKey: MK_Error,
    93  	Delims:       DefaultDelimiters,
    94  }