Skip to content

Latest commit

 

History

History
166 lines (141 loc) · 5.62 KB

tinytex.org

File metadata and controls

166 lines (141 loc) · 5.62 KB

TinyTeX module

Convenience functions for TinyTeX.

I have started using TinyTeX to avoid having a gigantic TeX/LaTeX distribution on my system. This module has some convenience functions I have written to automate some things.

Table of Contents

Usage

Install the elvish-modules package using epm:

use epm
epm:install github.com/zzamboni/elvish-modules

In your rc.elv, load this module:

use github.com/zzamboni/elvish-modules/tinytex

For now, the only function is tinytex:install-by-file, which takes a filename, searches for the package which contains that file, and installs it. If only one package matches the file, everything happens automatically:

[~]─> tinytex:install-by-file ifmtarg.sty
Installing package ifmtarg
tlmgr: package repository http://mirror.kumi.systems/ctan/systems/texlive/tlnet (verified)
[1/1, ??:??/??:??] install: ifmtarg [1k]
running mktexlsr ...
done running mktexlsr.
tlmgr: package log updated: /Users/taazadi1/Library/TinyTeX/texmf-var/web2c/tlmgr.log

If more than one package matches the file, it shows you the search results, and you can choose which of the matching packages you want to install:

[~]─> tinytex:install-by-file biber
There are multiple packages which contain a matching file:
tlmgr: package repository http://mirror.kumi.systems/ctan/systems/texlive/tlnet (verified)
0) 00texlive.image:
	tlpkg/tlpsrc/biber.tlpsrc
1) arara:
	texmf-dist/scripts/arara/rules/biber.yaml
2) biber:
	texmf-dist/doc/bibtex/biber/biber.pdf
	texmf-dist/source/bibtex/biber/Changes
	texmf-dist/source/bibtex/biber/README.md
	texmf-dist/source/bibtex/biber/biblatex-biber.tar.gz
	texmf-dist/source/bibtex/biber/utf8-macro-map.html
3) biber.amd64-freebsd:
	bin/amd64-freebsd/biber
4) biber.i386-cygwin:
	bin/i386-cygwin/biber.exe
5) biber.i386-freebsd:
	bin/i386-freebsd/biber
...
17) dickimaw:
	texmf-dist/doc/latex/dickimaw/src/thesis/pictures/bibertool.png
Please enter the numbers of the packages to install (comma-or-space-separated,
empty to cancel): 2
Packages selected: biber
Installing package biber
tlmgr: package repository http://mirror.kumi.systems/ctan/systems/texlive/tlnet (verified)
[1/2, ??:??/??:??] install: biber.x86_64-darwin [27656k]
[2/2, 00:13/00:13] install: biber [1k]
tlmgr: package log updated: /Users/taazadi1/Library/TinyTeX/texmf-var/web2c/tlmgr.log

Implementation

Load libraries

use re
use str

Install TinyTex

Detect which utility to use, and run the appropriate command.

fn install {
  var opt = ""
  var url = "https://yihui.org/gh/tinytex/tools/install-unx.sh"
  if ?(var cmd = (which curl)) {
    set opt = "-sL"
  } elif ?(set cmd = (which wget)) {
    set opt = "-qO-"
  } else {
    echo "I couldn't find curl nor wget in your path."
    exit 1
  }
  echo (styled "Installing TinyTeX with `"$cmd" "$opt" "$url" | sh`" green)
  (external $cmd) $opt $url | sh
}

Install missing packages by file

If a LaTeX compile tells me a certain file is missing, I can just type tinytex:install-by-file <file>, which automates searching for the package which contains the file, and then installing it.

fn install-by-file {|f|
  var search-res = [(tlmgr search --global --file "/"$f )]
  var pkgs = [(each {|l| if (eq $l[-1] ":") { put $l[0..-1] } } $search-res)]
  if (> (count $pkgs) 1) {
    var i = 0
    echo (styled "There are multiple packages which contain a matching file:" blue)
    each {|l|
      if (eq $l[-1] ":") {
        echo (styled $i") "$l yellow)
        set i = (+ $i 1)
      } else {
        echo $l
      }
    } $search-res
    print (styled "Please enter the numbers of the packages to install (comma-or-space-separated, empty to cancel): " blue)
    var resp = (read-upto "\n")[0..-1]
    set pkgs = [(re:split "[, ]+" $resp | each {|n| if (not-eq $n '') { put $pkgs[$n] } })]
    if (> (count $pkgs) 0) {
      echo (styled "Packages selected: "(str:join ", " $pkgs) yellow)
    }
  }
  each {|pkg|
    echo (styled "Installing package "$pkg blue)
    tlmgr install $pkg
  } $pkgs
}

Install missing packages based on LaTeX output

If you have a file that is missing a few packages, you can repeatedly pipe its output into tinytex:install-missing-file to automatically capture the missing file and call tinytex:install-by-file to install the corresponding package.

This is to be used like this:

latex file.tex | tinytex:install-missing-file
fn install-missing-file {
  each {|l|
    echo $l
    if (re:match 'LaTeX Error:.*not found' $l) {
      var pkg = (re:find 'LaTeX Error: File `(.*)'' not found' $l)[groups][1][text]
      echo (styled "Type 'x' and press Enter to install the missing file "$pkg yellow)
      install-by-file $pkg
    }
  }
}