From d429c2e21b9636cffa27a8d4f063644b8bcecf1a 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 | 10 ++++++---- resources/page.latex | 2 +- resources/unicodemapping.tex | 14 ++++++++++++++ shell.nix | 8 ++++++-- 4 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 resources/unicodemapping.tex diff --git a/Makefile b/Makefile index 2512d69..5698724 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ IFORMAT = markdown TEMPLATE = resources/page.tmpl LTEMPLATE = resources/page.latex ETEMPLATE = resources/page.epubt +UNICODE_MAP = resources/unicodemapping.tex FLAGS = --standalone \ --toc \ --toc-depth=2 \ @@ -12,10 +13,11 @@ FLAGS = --standalone \ GHC=ghc HTML = tutorial.html +PDF = tutorial.pdf # Check if sandbox exists. If it does, then use it instead. -all: $(HTML) +all: $(HTML) $(PDF) includes: includes.hs $(GHC) --make $< ; \ @@ -30,14 +32,14 @@ includes: includes.hs | $(PANDOC) -f $(IFORMAT) -t epub $(FLAGS) -o $@ %.pdf: %.md includes - ./includes < $< | $(PANDOC) -c -s -f $(IFORMAT) --template $(LTEMPLATE) --latex-engine=xelatex $(FLAGS) -o $@ + ./includes < $< | $(PANDOC) -c -s -f $(IFORMAT) --template $(LTEMPLATE) --include-in-header $(UNICODE_MAP) --pdf-engine=xelatex $(FLAGS) -o $@ clean: - -rm $(CHAPTERS) $(HTML) + -rm $(CHAPTERS) $(HTML) $(PDF) # pandoc executable 'includes' is rather large clean-all: - rm -rf $(CHAPTERS) $(HTML) includes + rm -rf $(CHAPTERS) $(HTML) $(PDF) includes # NIX BUILD # Enter nix shell with 'make run-shell' first (then 'make all') 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)