cat /dev/brain |

ad-hoc texdoc

published on Sunday, February 5, 2017

Archlinux does not include documentation for tex packages. Therefore, native texdoc does not work:

% texdoc siunitx
Sorry, no documentation found for siunitx.
If you are unsure about the name, try searching CTAN's TeX catalogue at

Consider using this (very primitive) replacement for texdoc:


function texdoc
                     'Pack­age doc­u­men­ta­tion') &&
    mkdir -p $prefix
    cache=$prefix/$(basename $doc) && (
    if [[ ! -e $cache ]]; then
        wget $doc -O $cache
    ) &&
    evince $cache

It will download documentation from CTAN and save it in your ~/.texdoc/ folder for future use.

The function has one more dependency, download this simple utility script and make it executable:


#! /usr/bin/env python
# encoding: utf-8

Get link by text content.

    hrefbytext URL TEXT

    hrefbytext "" \
               "Pack­age doc­u­men­ta­tion"

import sys
from urllib.request import urlopen
from lxml.html import parse, fromstring

def main(args):
    url = args[0]
    doc = parse(urlopen(url)).getroot()
    text = fromstring(args[1]).text_content()   # replace HTML entities
    for link in doc.cssselect('a'):
        if link.text_content() == text:

if __name__ == '__main__':

In fact, I recommend saving it to ~/bin/ and adding that folder to your PATH:


path=($path ~/bin)

This entry was tagged config, gist, helper, tex, util and zsh