From 8009d676782ad6d3dc4622ce3146f7c0ab1f6eba Mon Sep 17 00:00:00 2001 From: Igal Tabachnik Date: Thu, 16 Jan 2020 16:49:01 +0200 Subject: [PATCH] Fixing missing unicode characters in rendered PDF (#177) * Tweaking fonts to support unicode characters + making it pretty * Adding unicode mapping to math symbols for missing characters * Trying older ghc to fix the CI build issues --- Makefile | 4 +++- resources/page.latex | 2 +- resources/unicodemapping.tex | 14 ++++++++++++++ shell.nix | 8 ++++++-- 4 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 resources/unicodemapping.tex diff --git a/Makefile b/Makefile index 1265e35..df9adad 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,8 @@ HTEMPLATE = resources/page.tmpl LTEMPLATE = resources/page.latex ETEMPLATE = resources/page.epubt +UNICODE_MAP = resources/unicodemapping.tex + FLAGS = --standalone --toc --toc-depth=2 --highlight-style pygments LFLAGS = --top-level-division=chapter -V documentclass=book HFLAGS = -c css/style.css -c css/layout.css @@ -33,7 +35,7 @@ includes: includes.hs | $(PANDOC) -f $(IFORMAT) -t epub $(FLAGS) $(EFLAGS) -o $@ %.pdf: %.md includes - ./includes < $< | $(PANDOC) -c -s -f $(IFORMAT) --template $(LTEMPLATE) --pdf-engine=xelatex $(FLAGS) $(LFLAGS) -o $@ + ./includes < $< | $(PANDOC) -c -s -f $(IFORMAT) --template $(LTEMPLATE) --include-in-header $(UNICODE_MAP) --pdf-engine=xelatex $(FLAGS) $(LFLAGS) -o $@ clean: -rm -f $(CHAPTERS) $(HTML) $(PDF) $(EPUB) diff --git a/resources/page.latex b/resources/page.latex index 58a40ad..4f3b6db 100644 --- a/resources/page.latex +++ b/resources/page.latex @@ -11,7 +11,6 @@ $if(linestretch)$ $endif$ \usepackage{amssymb,amsmath} \usepackage{ifxetex,ifluatex} -\usepackage{fixltx2e} % provides \textsubscript \ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex \usepackage[$if(fontenc)$$fontenc$$else$T1$endif$]{fontenc} \usepackage[utf8]{inputenc} @@ -25,6 +24,7 @@ $endif$ \usepackage{fontspec} \fi \defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase} + \setmonofont{DejaVu Sans Mono} $if(euro)$ \newcommand{\euro}{€} $endif$ diff --git a/resources/unicodemapping.tex b/resources/unicodemapping.tex new file mode 100644 index 0000000..28e9140 --- /dev/null +++ b/resources/unicodemapping.tex @@ -0,0 +1,14 @@ +\newcommand{\sbullet}{% + \texorpdfstring{\textsbullet}{\textbullet}% +} +\DeclareRobustCommand{\textsbullet}{% + \unskip~\,\begin{picture}(1,1)(0,-3)\circle*{3}\end{picture}\ % +} +\usepackage{newunicodechar} +\newunicodechar{⊥}{\ensuremath{\bot}} +\newunicodechar{⊤}{\ensuremath{\top}} +\newunicodechar{∨}{\ensuremath{\vee}} +\newunicodechar{∧}{\ensuremath{\wedge}} +\newunicodechar{⇒}{\ensuremath{\Rightarrow}} +\newunicodechar{•}{\ensuremath{\sbullet}} +\newunicodechar{λ}{\ensuremath{\lambda}} \ No newline at end of file diff --git a/shell.nix b/shell.nix index 0b7b5f7..ef5d2cd 100644 --- a/shell.nix +++ b/shell.nix @@ -1,18 +1,22 @@ -{ nixpkgs ? , compiler ? "ghc843" }: +{ pkgs ? import {}, compiler ? "ghc843" }: with pkgs; let - pkgs = import nixpkgs { }; ghcWithDeps = pkgs.haskell.packages.${compiler}.ghcWithPackages ( ps: with ps; [ base pandoc containers ] ); tex = with pkgs; texlive.combine { inherit (texlive) scheme-small xetex + newunicodechar ; }; + fontsConf = makeFontsConf { + fontDirectories = [ dejavu_fonts ]; + }; in pkgs.stdenv.mkDerivation { name = "wiwinwlh-env"; buildInputs = [ ghcWithDeps tex ]; + FONTCONFIG_FILE = fontsConf; shellHook = '' export LANG=en_US.UTF-8 eval $(egrep ^export ${ghcWithDeps}/bin/ghc)