Skip to content

Instantly share code, notes, and snippets.

@tobywf
Last active April 26, 2024 10:14
Show Gist options
  • Save tobywf/aeeeee63053aaaa841b4032963406684 to your computer and use it in GitHub Desktop.
Save tobywf/aeeeee63053aaaa841b4032963406684 to your computer and use it in GitHub Desktop.
Build dvisvgm and kpathsea on macOS
#!/bin/bash
set -xeuo pipefail
IFS=$'\n\t'
PREFIX="${1:-/usr/local/dvisvgm}"
TEX="$(kpsewhich -var SELFAUTOLOC)"
echo "$PREFIX, $TEX"
brew install automake freetype ghostscript potrace
# download the sources
mkdir -p "$PREFIX/source/texk"
cd "$PREFIX/source/"
# see https://www.tug.org/texlive/svn/
rsync -av --exclude=.svn tug.org::tldevsrc/Build/source/build-aux .
rsync -av --exclude=.svn tug.org::tldevsrc/Build/source/texk/kpathsea texk/
git clone git@github.com:mgieseki/dvisvgm.git
# compile kpathsea
cd texk/kpathsea
# patch SELFAUTOLOC
perl -0777 -i.bak \
-pe 's|(kpathsea_selfdir \(kpathsea kpse, const_string argv0\)\n{)|$1\n return xstrdup("'"$TEX"'");\n|g' \
progname.c
./configure --prefix="$PREFIX/"
make
make install
# compile dvisvgm
cd ../../dvisvgm
./autogen.sh
CPPFLAGS="-I$PREFIX/include/" LDFLAGS="-L$PREFIX/lib/" ./configure --prefix="$PREFIX/"
make
make check
make install
@tobywf
Copy link
Author

tobywf commented Nov 19, 2019

Awesome, glad it helps! That's great tip. I think the WOFF stuff was added shortly after I originally published this in April 2017. Hopefully I'll get some time to re-run this with the latest sources.

@maximechoulika
Copy link

maximechoulika commented Jan 6, 2020

For kpsewhich: option '-var' is ambiguous , just replace -var with -var-value, and it works.

@iamtekeste
Copy link

Thank you @tobywf for this script and @Talasta @Nowaday for the fixes too.

@wtroughton
Copy link

The perl regex fails due to unmatched left brace. Falling back to an older version of perl before 5.24 should work.

@SterlingHooten
Copy link

SterlingHooten commented Nov 19, 2021

The perl regex fails due to unmatched left brace. Falling back to an older version of perl before 5.24 should work.

Escaping the left open brace '{' with a backslash \ works with perl 5.34 on macos 11.2.3
-pe 's|(kpathsea_selfdir \(kpathsea kpse, const_string argv0\)\n\{)|$1\n return xstrdup("'"$TEX"'");\n|g' \

@jasoneveleth
Copy link

jasoneveleth commented Feb 5, 2022

I found that this wouldn't work unless I put the binary at $(kpsewhich -var-value SELFAUTOLOC) and then made a symbolic link to it.

@AdelleBernal
Copy link

I got this :(¨


+ IFS='
	'
+ PREFIX=/usr/local/dvisvgm
++ kpsewhich -var SELFAUTOLOC
kpsewhich: option `-var' is ambiguous
+ TEX=

@AdelleBernal
Copy link

-var-value

It worked!

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