replace dockers/MathJaxFonts with KaTeX/katex-fonts submodule (#891)

This commit is contained in:
Kevin Barabash
2017-11-28 07:25:03 -05:00
committed by GitHub
parent 4cbc4d3cd9
commit 9e6eb3a219
89 changed files with 30 additions and 238 deletions

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "submodules/katex-fonts"]
path = submodules/katex-fonts
url = https://github.com/KaTeX/katex-fonts

View File

@@ -131,6 +131,29 @@ In general, try to make your code blend in with the surrounding code.
- commits should be squashed before merging
- large pull requests should be broken into separate pull requests (or multiple logically cohesive commits), if possible
## Working with submodules
The fonts for KaTeX live in a submodule which appears in submodules/katex-fonts.
Most of the time you won't have to worry about this unless you're making
changes to fonts or switching between branches where submodules/katex0fonts
point to different commits.
If you're not familiar with submodule, it's probably easiest to get started by
adding the following aliases to your .gitconfig:
```
[alias]
# Versions of commands that handle submodules properly.
co = "!f() { git checkout \"$@\" && git submodule update --init --recursive; }; f"
p = "!f() { git pull \"$@\" && git submodule update --init --recursive; }; f"
m = "!f() { git merge \"$@\" && git submodule update --init --recursive; }; f"
gsu = "!f() { git submodule sync --recursive && git submodule update --init --recursive; }; f"
```
`git co`, `git p`, and `git m` work just like `git checkout`, `git pull`, and
`git merge` respectively but automatically update submodules. For more info
about how to use git submodules see https://chrisjean.com/git-submodules-adding-using-removing-and-updating/.
When submitting pull requests, that update katex-fonts, you'll need to submit
two pull requests: one for [KaTeX/katex-fonts](https:/github.com/KaTeX/katex-fonts) and one for [Khan/KaTeX](https://github.com/Khan/KaTeX).
## CLA
In order to contribute to KaTeX, you must first sign the CLA, found at www.khanacademy.org/r/cla

View File

@@ -61,7 +61,7 @@ build/fonts:
rm -rf $@
mkdir $@
for font in $(shell grep "font" static/katex.less | grep -o "KaTeX_\w\+" | cut -d" " -f 2 | sort | uniq); do \
cp static/fonts/$$font* $@; \
cp submodules/katex-fonts/fonts/$$font* $@; \
done
test/screenshotter/unicode-fonts:

View File

@@ -1,66 +0,0 @@
FROM ubuntu:14.04
MAINTAINER xymostech <xymostech@gmail.com>
# Install things
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get -y upgrade \
&& DEBIAN_FRONTEND=noninteractive apt-get -y install \
--no-install-recommends --auto-remove \
git \
dvipng \
default-jre \
default-jdk \
texlive \
wget \
fontforge \
mftrace \
fonttools \
optipng \
advancecomp \
man-db \
build-essential \
unzip \
zlib1g-dev \
python-fontforge \
ruby \
woff-tools \
pkg-config \
libharfbuzz-dev \
libfreetype6-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& gem install ttfunk --version 1.1.1
# Download yuicompressor
ADD https://github.com/yui/yuicompressor/releases/download/v2.4.8/yuicompressor-2.4.8.jar /usr/share/yui-compressor/yui-compressor.jar
# Download batik-ttf2svg.jar
RUN wget "https://archive.apache.org/dist/xmlgraphics/batik/batik-1.7.zip" \
&& unzip batik-*.zip batik-*/batik-ttf2svg.jar \
&& mv batik-*/batik-ttf2svg.jar /usr/share/java/ \
&& rm -r batik-*
# Download and compile ttf2eof (note we add a patch to make it compile)
RUN wget "https://github.com/wget/ttf2eot/archive/v0.0.2-2.tar.gz" -O ttf2eot.tar.gz\
&& tar -xzf ttf2eot.tar.gz \
&& sed -i "1s/^/#include <cstddef>/" ttf2eot-*/OpenTypeUtilities.h \
&& make -C ttf2eot-*/ \
&& mv ttf2eot-*/ttf2eot /usr/bin/ \
&& rm -r ttf2eot*
# Download and compile ttfautohint
RUN wget "http://download.savannah.gnu.org/releases/freetype/ttfautohint-1.3.tar.gz" \
&& tar -xzf ttfautohint-*.tar.gz \
&& cd ttfautohint-*/ \
&& ./configure --without-qt \
&& make \
&& mv frontend/ttfautohint /usr/bin \
&& cd .. \
&& rm -r ttfautohint-*
# Download and compile woff2_compress
RUN wget "https://github.com/google/woff2/archive/d9a74803fa884559879e3205cfe6f257a2d85519.tar.gz" -O woff2.tar.gz \
&& tar -xzf woff2.tar.gz \
&& make -C woff2-*/woff2/ \
&& mv woff2-*/woff2/woff2_compress /usr/bin \
&& rm -r woff2*

View File

@@ -1,22 +0,0 @@
### How to generate MathJax fonts
---------------------------------
The `buildFonts.sh` script should do everything automatically,
as long as Docker is installed.
If you want to try out a change
to [the MathJax-dev repository](https://github.com/Khan/MathJax-dev),
create a local clone (or download and unpack the ZIP file)
and specify the path to this directory as an arument to `buildFonts.sh`.
You can also specify a local or remote tarball,
e.g. a GitHub download of your own personal feature branch.
The script `buildFonts.sh` automatically creates Docker images
from the supplied `Dockerfile`.
It uses the hash of the file to tag the image, so a change to the file
will result in the creation of a new image.
If you want to see all created images, run `docker images katex/fonts`.
To remove all generated images, you can run
`docker rmi $(docker images --format '{{.Repository}}:{{.Tag}}' katex/fonts)`.
If there is a problem, file a bug report.

View File

@@ -1,148 +0,0 @@
#!/usr/bin/env bash
shopt -s extglob
usage() {
while [[ $# -gt 1 ]]; do
echo "$1" >&2
shift
done
echo "Usage: ${0##*/} [OPTIONS] [SOURCE]"
echo ""
echo "SOURCE may be"
echo " - a URL for a tarball, or"
echo " - a local tarball file, or"
echo " - a local directory"
echo "with a layout compatible to MathJax-dev."
echo "It defaults to ${URL}"
echo ""
echo "OPTIONS:"
echo " -h|--help display this help"
echo " --image NAME:TAG use the named docker image [$IMAGE]"
exit $1
}
used_fonts=(
KaTeX_AMS-Regular
KaTeX_Caligraphic-Bold
KaTeX_Caligraphic-Regular
KaTeX_Fraktur-Bold
KaTeX_Fraktur-Regular
KaTeX_Main-Bold
KaTeX_Main-Italic
KaTeX_Main-Regular
KaTeX_Math-BoldItalic
KaTeX_Math-Italic
KaTeX_Math-Regular
KaTeX_SansSerif-Bold
KaTeX_SansSerif-Italic
KaTeX_SansSerif-Regular
KaTeX_Script-Regular
KaTeX_Size1-Regular
KaTeX_Size2-Regular
KaTeX_Size3-Regular
KaTeX_Size4-Regular
KaTeX_Typewriter-Regular
)
filetypes=( ttf eot woff woff2 )
set -e
cd "$(dirname "$0")"
cleanup() {
[[ "${CONTAINER}" ]] \
&& docker stop "${CONTAINER}" >/dev/null \
&& docker rm "${CONTAINER}" >/dev/null
CONTAINER=
[[ -f "${TMPFILE}" ]] && rm "${TMPFILE}"
TMPFILE=
}
CONTAINER=
trap cleanup EXIT
IMAGE="katex/fonts:DF-$(openssl sha1 Dockerfile | tail -c 9)"
URL=https://github.com/Khan/MathJax-dev/archive/master.tar.gz
TMPFILE=
FILE=
NARGS=0
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
usage 0
;;
--image=*)
IMAGE="${1#*=}"
;;
--image)
shift
IMAGE="$1"
;;
-*)
usage "Invalid option: $1" "" 1
;;
*)
case $NARGS in
0)
if [[ -d "$1" ]]; then
TMPFILE="$(mktemp "${TMPDIR:-/tmp}/mjf.XXXXXXXX")"
FILE="$TMPFILE"
pushd "$1"
if [[ ! -f fonts/OTF/TeX/Makefile ]]; then
echo "$1 does not look like MathJax-dev" >&2
exit 1
fi
tar cf "$FILE" Makefile default.cfg fonts/OTF/TeX
popd
elif [[ -f "$1" ]]; then
FILE="$1"
elif [[ "$1" = http?(s)://* ]]; then
URL="$1"
else
echo "'$1' is not a valid source" >&2
exit 1
fi
NARGS=1
;;
*)
usage "Too many arguments: $1" "" 1
;;
esac
;;
esac
shift
done
# build image if missing
if [[ $(docker images "$IMAGE" | wc -l) -lt 2 ]]; then
echo "Need to build docker image $IMAGE"
docker build --tag "$IMAGE" .
fi
CMDS="set -ex
test -f MathJax-dev.tar.gz || wget -O MathJax-dev.tar.gz '${URL}'
mk=\$(tar tf MathJax-dev.tar.gz | grep 'fonts/OTF/TeX/Makefile\$')
tar xf MathJax-dev.tar.gz
cd \"\${mk%fonts/*}\"
cp default.cfg custom.cfg
make custom.cfg.pl
make -C fonts/OTF/TeX ${filetypes[*]}
tar cf /fonts.tar ${filetypes[*]/#/fonts/OTF/TeX/}"
echo "Creating and starting docker container from image $IMAGE"
CONTAINER=$(docker create "$IMAGE" /bin/sh -c "${CMDS}")
if [[ ${FILE} ]]; then
docker cp "${FILE}" $CONTAINER:/MathJax-dev.tar.gz
fi
docker start --attach $CONTAINER
docker cp $CONTAINER:/fonts.tar .
cleanup
echo "Docker executed successfully, will now unpack the fonts"
tar xf fonts.tar
for filetype in "${filetypes[@]}"; do
for font in "${used_fonts[@]}"; do
echo "$filetype/$font"
mv "fonts/OTF/TeX/$filetype/$font".* ../../static/fonts/
done
done
rm -rf fonts fonts.tar

View File

@@ -60,7 +60,7 @@ def main():
start_json = json.load(sys.stdin)
for font, chars in metrics_to_extract.iteritems():
fontInfo = TTFont("../static/fonts/KaTeX_" + font + ".ttf")
fontInfo = TTFont("../submodules/katex-fonts/fonts/KaTeX_" + font + ".ttf")
glyf = fontInfo["glyf"]
unitsPerEm = float(fontInfo["head"].unitsPerEm)

1
static/fonts Symbolic link
View File

@@ -0,0 +1 @@
../submodules/katex-fonts/fonts

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.