Skip to content

Instantly share code, notes, and snippets.

@gramian
Last active April 23, 2017 08:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save gramian/028870c77620598384eb to your computer and use it in GitHub Desktop.
Save gramian/028870c77620598384eb to your computer and use it in GitHub Desktop.
A small script to use the hack truetype font in pdflatex
#!/bin/sh
# hack4tex 0.1
# Copyright (c) 2016 Christian Himpe
# released under BSD 2-Clause License ( opensource.org/licenses/BSD-2-Clause )
# based on Stephan Lehmke's answer to "How do I use TrueType Fonts with PDFTeX
# using otftotfm?" on tex.stackexchange.com/a/52902
#
# requires otftotfm which is part of lcdf-typetools
#
# copy tex4hack and Hack-*.ttf to some folder and run hack4tex
#
# copy t1hack.fd and Hack-*.ttf to document folder
#
# use in pdflatex with
# \pdfmapfile{hack.map}
# \renewcommand\ttdefault{Hack} % for example
otftotfm -a -e ec -fkern -fliga --verbose --vendor hack Hack-Regular.ttf T1--Hack--Regular &>> hack.log
otftotfm -a -e ec -fkern -fliga --verbose --vendor hack Hack-Bold.ttf T1--Hack--Bold &>> hack.log
otftotfm -a -e ec -fkern -fliga --verbose --vendor hack Hack-Italic.ttf T1--Hack--Italic &>> hack.log
otftotfm -a -e ec -fkern -fliga --verbose --vendor hack Hack-BoldItalic.ttf T1--Hack--BoldItalic &>> hack.log
echo "\ProvidesFile{t1hack.fd}
\DeclareFontFamily{T1}{Hack}{}
\DeclareFontShape{T1}{Hack}{m}{n}{
<-> T1--Hack--Regular
}{}
\DeclareFontShape{T1}{Hack}{b}{n}{
<-> T1--Hack--Bold
}{}
\DeclareFontShape{T1}{Hack}{m}{sl}{
<-> T1--Hack--Italic
}{}
\DeclareFontShape{T1}{Hack}{b}{sl}{
<-> T1--Hack--BoldItalic
}{}" > t1hack.fd
@chrissimpkins
Copy link

Added a statement about where users can find the ttf fonts to your gist header documentation over here:

https://gist.github.com/chrissimpkins/1dceed5c303179f2084f

This might be helpful if they reach your script through a site other than the Hack documentation. Thought there might be a way to PR this back to you in a gist but it appears not. Just a suggestion. Feel free to take it or leave it.

@BendingBender
Copy link

Please consider changing the shebang to #!/usr/bin/env bash or #!/usr/bin/bash, otherwise the hack.log file stays empty on a Linux system and all output is instead printed to the console. Tested with Ubuntu Linux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment