From 33b09a1c89b5819c9f8228a6fa0eb1f4ea862dd4 Mon Sep 17 00:00:00 2001
From: Vincent Danjean <Vincent.Danjean@ens-lyon.org>
Date: Sun, 8 Jan 2017 22:38:46 +0100
Subject: [PATCH] Add lualatex support

Lualatex should be handled nearly as pdflatex as reported
by Andreas Beckmann in https://bugs.debian.org/815836

A new LUALATEX flavor is now defined.
To use it instead of pdflatex, one just have to set 'LU_FLAVORS=LUALATEX'
Of course, flavors can be chosen per document if need be (as in the example directory)
---
 .gitignore                    |  1 +
 examples/Makefile             |  5 ++++-
 examples/lualatex-example.tex |  8 ++++++++
 src/latex-make.dtx            | 20 ++++++++++++++++++--
 4 files changed, 31 insertions(+), 3 deletions(-)
 create mode 100644 examples/lualatex-example.tex

diff --git a/.gitignore b/.gitignore
index e2786a5..b02b2a0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,6 +11,7 @@
 /src/latex-make.pdf
 /src/texdepends.pdf
 /examples/example.pdf
+/examples/lualatex-example.pdf
 /examples/bin/
 /examples/*.sty
 /examples/LaTeX.mk
diff --git a/examples/Makefile b/examples/Makefile
index 6d83836..6579892 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -1,7 +1,10 @@
 
 #COMPATIBILITY=true
 
-all: example.pdf
+# example-luatex must be compiled with lualatex
+LU_lualatex-example_FLAVORS=LUALATEX
+
+all: pdf
 
 example.pdf:
 
diff --git a/examples/lualatex-example.tex b/examples/lualatex-example.tex
new file mode 100644
index 0000000..ef7a2c6
--- /dev/null
+++ b/examples/lualatex-example.tex
@@ -0,0 +1,8 @@
+\documentclass{article}
+\usepackage{luacode}
+\begin{document}
+A random number:
+\begin{luacode}
+tex.print(math.random())
+\end{luacode}
+\end{document}
diff --git a/src/latex-make.dtx b/src/latex-make.dtx
index 73c0b5d..bb17742 100644
--- a/src/latex-make.dtx
+++ b/src/latex-make.dtx
@@ -101,7 +101,7 @@
 % documents with the help of a Makefile. Dependencies are
 % automatically tracked with the help of the |texdepends.sty| package.
 % \end{abstract}
-% \CheckSum{323}
+% \CheckSum{332}
 %
 % \changes{v2.0.0}{2006/03/09}{First autocommented version}
 % \changes{v2.1.0}{2008/01/28}{That's the question}
@@ -289,6 +289,8 @@
 %     \hline
 %     PDF & & PDFLATEX & |.tex| $\Rightarrow$ |.pdf| \\
 %     \hline
+%     LUALATEX & & LUALATEX & |.tex| $\Rightarrow$ |.pdf| \\
+%     \hline
 %     DVIPDF & DVI & DVIPDFM & |.dvi| $\Rightarrow$ |.pdf| \\
 %     \hline
 %   \end{tabular}
@@ -422,6 +424,14 @@
 % endef
 % \end{source}
 % 
+% \paragraph{LuaLaTeX flavor}
+% \begin{source}[0.9\linewidth]
+% define lu-define-flavor-LUALATEX\\
+% \hspace*{2ex}\$\$(eval \$\$(call lu-create-flavor,LUALATEX,tex,LUALATEX,.pdf,pdf,\textbackslash\\
+% \hspace*{4ex}.pdftex\_t .\$\$(\_LU\_PDFTEX\_EXT)))\\
+% endef
+% \end{source}
+% 
 % \paragraph{PS flavor}
 % \begin{source}[0.9\linewidth]
 % define lu-define-flavor-PS\\
@@ -1094,6 +1104,7 @@ endef
 # Globals variables
 $(eval $(call lu-setvar-global,LATEX,latex))
 $(eval $(call lu-setvar-global,PDFLATEX,pdflatex))
+$(eval $(call lu-setvar-global,LUALATEX,lualatex))
 $(eval $(call lu-setvar-global,DVIPS,dvips))
 $(eval $(call lu-setvar-global,DVIPDFM,dvipdfm))
 $(eval $(call lu-setvar-global,BIBTEX,bibtex))
@@ -1198,6 +1209,11 @@ define lu-define-flavor-PDF #
 	.pdftex_t .$$(_LU_PDFTEX_EXT)))
 endef
 
+define lu-define-flavor-LUALATEX #
+  $$(eval $$(call lu-create-flavor,LUALATEX,tex,LUALATEX,.pdf,pdf,\
+	.pdftex_t .$$(_LU_PDFTEX_EXT)))
+endef
+
 define lu-define-flavor-PS #
   $$(eval $$(call lu-create-flavor,PS,dvi,DVIPS,.ps,ps,DVI))
 endef
@@ -1248,7 +1264,7 @@ define _lu-do-latex # 1:master 2:flavor 3:source.tex 4:ext(.dvi/.pdf)
 	if [ ! -f "$(1)$(4).mk" ]; then \
 		NO_TEXDEPENDS_FILE=1 ;\
 	fi ;\
-	sed -e 's,\\openout[0-9]* = `\(.*\)'"'.,TD_$(1)$(4)_OUTPUTS += \1,p;d" \
+	sed -e 's,\\openout[0-9]* = \([^`].*\),TD_$(1)$(4)_OUTPUTS += \1,p;s,\\openout[0-9]* = `\(.*\)'"'.,TD_$(1)$(4)_OUTPUTS += \1,p;d" \
 		"$(1).log" >> "$(1)$(4).mk" ;\
 	if [ -f "$(1)$(4)_FAILED" ]; then \
 		echo "*************************************" ;\
-- 
GitLab