From 977ca41b2356288f6d8d8dbbee0c0f39e276f45c Mon Sep 17 00:00:00 2001 From: j8takagi <j8takagi@nifty.com> Date: Tue, 26 Nov 2013 20:31:43 +0900 Subject: [PATCH] =?utf8?q?latex.mk=E3=81=AE=E6=8E=A8=E6=95=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- latex_mk/latex.mk | 164 ++++++++++++++++++++++++++++++---------------- 1 file changed, 108 insertions(+), 56 deletions(-) diff --git a/latex_mk/latex.mk b/latex_mk/latex.mk index b477457..19b15ad 100644 --- a/latex_mk/latex.mk +++ b/latex_mk/latex.mk @@ -57,6 +57,9 @@ MENDEXFLAG ?= tex-warning: @$(ECHO) "check current directory, or set TEXTARGET in Makefile." +# ãã¡ã¤ã«åããæ¡å¼µåãé¤ããé¨å +BASE = $(basename $<) + # TeXä¸éãã¡ã¤ã«ã®æ¡å¼µå # .aux: ç¸äºåç § # .fls: tex -recorderã§çæããããã¡ã¤ã«ãªã¹ã @@ -81,41 +84,101 @@ ALL_INTERFILES = $(addprefix *,$(TEX_INT) $(IND_INT) $(BIB_INT) .d .*_prev) .SECONDARY: $(wildcard ALL_INTERFILES) # \tableofcontentså½ä»¤ãTeXãã¡ã¤ã«ããæ¤ç´¢ãã -toc = $(shell $(SED) -n -e '/^.*[^\]\{0,1\}%.*\\tableofcontents/!s/.*\(\\tableofcontents\).*/\1/p' $< $(intex)) +toc = \ + $(shell \ + $(SED) -e '/^\s*%/d' -e 's/\([^\]\)\s*%.*/\1/g' $(BASE).tex $(intex) | \ + $(SED) -e '/\\begin{verbatim}/,/\\end{verbatim}/d' | \ + $(SED) -n -e 's/.*\(\\tableofcontents\)/\1/p' \ + ) # \listoffigureså½ä»¤ãTeXãã¡ã¤ã«ããæ¤ç´¢ãã -lof = $(shell $(SED) -n -e '/^.*[^\]\{0,1\}%.*\\listoffigures/!s/.*\(\\listoffigures\).*/\1/p' $< $(intex)) +lof = \ + $(shell \ + $(SED) -e '/^\s*%/d' -e 's/\([^\]\)\s*%.*/\1/g' $(BASE).tex $(intex) | \ + $(SED) -e '/\\begin{verbatim}/,/\\end{verbatim}/d' | \ + $(SED) -n -e 's/.*\(\\listoffigures\)/\1/p' \ + ) # \listoftableså½ä»¤ãTeXãã¡ã¤ã«ããæ¤ç´¢ãã -lot = $(shell $(SED) -n -e '/^.*[^\]\{0,1\}%.*\\listoftables/!s/.*\(\\listoftables\).*/\1/p' $< $(intex)) +lot = \ + $(shell \ + $(SED) -e '/^\s*%/d' -e 's/\([^\]\)\s*%.*/\1/g' $(BASE).tex $(intex) | \ + $(SED) -e '/\\begin{verbatim}/,/\\end{verbatim}/d' | \ + $(SED) -n -e 's/.*\(\\listoftables\)/\1/p' \ + ) # \makeindexå½ä»¤ãTeXãã¡ã¤ã«ããæ¤ç´¢ãã -makeindex = $(shell $(SED) -n -e '/^.*[^\]\{0,1\}%.*\\makeindex/!s/.*\(\\makeindex\).*/\1/p' $< $(intex)) +makeindex = \ + $(shell \ + $(SED) -e '/^\s*%/d' -e 's/\([^\]\)\s*%.*/\1/g' $(BASE).tex $(intex) | \ + $(SED) -e '/\\begin{verbatim}/,/\\end{verbatim}/d' | \ + $(SED) -n -e 's/.*\(\\makeindex\)/\1/p' \ + ) # \bibliographyå½ä»¤ã§èªã¿è¾¼ã¾ããæç®ãã¼ã¿ãã¼ã¹ãã¡ã¤ã«ãTeXãã¡ã¤ã«ããæ¤ç´¢ãã -bibdb = $(addsuffix .bib,$(basename $(strip $(shell \ - $(SED) -n -e '/^.*[^\]\{0,1\}%.*\\bibliography/!s/\\bibliography\(\[[^]]*\]\)\{0,1\}{\([^}]*\)}/&\n/p' $< $(intex) | \ - $(SED) -e 's/.*{\([^}]*\)}.*/\1/' | \ - $(SED) -e 's/,/ /g')))) +bibdb = \ + $(addsuffix .bib,$(basename $(strip $(shell \ + $(SED) -e '/^\s*%/d' -e 's/\([^\]\)\s*%.*/\1/g' $(BASE).tex $(intex) | \ + $(SED) -e '/\\begin{verbatim}/,/\\end{verbatim}/d' | \ + $(SED) -n -e 's/\\bibliography\(\[[^]]*\]\)\{0,1\}{[^}]*}/&\n/pg' | \ + $(SED) -n -e 's/.*{\([^}]*\)}$$/\1/p' | \ + $(SED) -e 's/,/ /g' \ + )))) # hyperrefããã±ã¼ã¸èªã¿è¾¼ã¿ãTeXãã¡ã¤ã«ããæ¤ç´¢ãã -hyperref = $(shell $(SED) -n -e '/^.*[^\]\{0,1\}%.*\\usepackage\(\[[^]]*\]\)\{0,1\}{hyperref}/!s/.*\(\\usepackage\)\(\[[^]]*\]\)\{0,1\}\({hyperref}\).*/\1\3/p' $< $(intex)) - -# ãã¡ã¤ã«åããæ¡å¼µåãé¤ããé¨å -BASE = $(basename $<) +hyperref = \ + $(shell \ + $(SED) -e '/^\s*%/d' -e 's/\([^\]\)\s*%.*/\1/g' $(BASE).tex $(intex) | \ + $(SED) -e '/\\begin{verbatim}/,/\\end{verbatim}/d' | \ + $(SED) -n -e 's/.*\(\\usepackage\(\[[^]]*\]\)\{0,1\}{hyperref}\)/\1/p'\ + ) # $(BASE).texã§ä½¿ãããLaTeXä¸éãã¡ã¤ã« -INTERFILES = $(strip \ - $(if $(toc),$(BASE).toc) \ - $(if $(lof),$(BASE).lof) \ - $(if $(lot),$(BASE).lot) \ - $(if $(makeindex),$(BASE).ind) \ - $(if $(bibdb),$(BASE).bbl) \ - $(if $(hyperref),$(BASE).out) \ - ) +INTERFILES = \ + $(strip \ + $(if $(toc),$(BASE).toc) \ + $(if $(lof),$(BASE).lof) \ + $(if $(lot),$(BASE).lot) \ + $(if $(makeindex),$(BASE).ind) \ + $(if $(bibdb),$(BASE).bbl) \ + $(if $(hyperref),$(BASE).out) \ + ) INTERFILES_PREV = $(addsuffix _prev,$(INTERFILES)) +# \includeå½ä»¤ã§èªã¿è¾¼ã¾ããTeXãã¡ã¤ã« +includetex = \ + $(strip $(addsuffix .tex,$(shell \ + $(SED) -e '/^\s*%/d' -e 's/\([^\]\)\s*%.*/\1/g' $(BASE).tex | \ + $(SED) -e '/\\begin{verbatim}/,/\\end{verbatim}/d' | \ + $(SED) -n -e 's/\\include\(\[[^]]*\]\)\{0,1\}{[^}]*}/&\n/pg' | \ + $(SED) -n -e 's/.*{\([^}]*\)}$$/\1/p' \ + ))) + +# \inputå½ä»¤ã§èªã¿è¾¼ã¾ããTeXãã¡ã¤ã« +define get_inputtex + $(strip $(shell \ + $(SED) -e '/^\s*%/d' -e 's/\([^\]\)\s*%.*/\1/g' $1 | \ + $(SED) -e '/\\begin{verbatim}/,/\\end{verbatim}/d' | \ + $(SED) -n -e 's/\\input\(\[[^]]*\]\)\{0,1\}{[^}]*}/&\n/pg' | \ + $(SED) -n -e 's/.*{\([^}]*\)}$$/\1/p' \ + )) +endef + +inputtex = $(call get_inputtex,$(BASE).tex $(includetex)) + +# \includeå½ä»¤ã¾ãã¯\inputå½ä»¤ã§èªã¿è¾¼ã¾ããTeXãã¡ã¤ã« +intex = $(strip $(includetex) $(inputtex)) + +# \includegraphicså½ä»¤ã§èªã¿è¾¼ã¾ããã°ã©ãã£ãã¯ãã¡ã¤ã« +ingraphics = \ + $(strip $(shell \ + $(SED) -e '/^\s*%/d' -e 's/\([^\]\)\s*%.*/\1/g' $(BASE).tex $(intex) | \ + $(SED) -e '/\\begin{verbatim}/,/\\end{verbatim}/d' | \ + $(SED) -n -e 's/\\includegraphics\(\[[^]]*\]\)\{0,1\}{[^}]*}/&\n/pg' | \ + $(SED) -n -e 's/.*{\([^}]*\)}$$/\1/p' \ + )) + # LaTeXå¦çï¼ã³ã³ãã¤ã«ï¼ LATEXCMD = $(LATEX) -interaction=batchmode $(LATEXFLAG) $(BASE).tex COMPILE.tex = $(ECHO) $(LATEXCMD); $(LATEXCMD) >/dev/null 2>&1 || ($(CAT) $(BASE).log; exit 1) @@ -125,7 +188,7 @@ WARN_UNDEFREF := 'There were undefined references\.' # LaTeXå¦ç # ãã°ãã¡ã¤ã«ã«è¦åãããå ´åã¯è¦åããªããªãã¾ã§ãæå¤§CNTã§æå®ãããåæ°åãå¦çãå®è¡ãã -CNT = 3 +CNT := 3 COMPILES.tex = \ @(for i in `$(SEQ) 1 $(CNT)`; do \ if test -s $@ -a -s $(BASE).log; then \ @@ -152,53 +215,42 @@ COMPILE.bib = $(ECHO) $(BIBTEXCMD); $(BIBTEXCMD) >/dev/null 2>&1 || ($(CAT) $(BA # ã¿ã¼ã²ãããã¡ã¤ã«ã¨å¿ é ãã¡ã¤ã«ãæ¯è¼ããå 容ãç°ãªãå ´åã¯ã¿ã¼ã²ãããã¡ã¤ã«ã®å 容ãå¿ é ãã¡ã¤ã«ã«ç½®ãæãã CMPPREV = $(CMP) $@ $< || $(CP) -p -v $< $@ -# \includeã\inputå½ä»¤ã§èªã¿è¾¼ã¾ããTeXãã¡ã¤ã« -intex = $(addsuffix .tex,$(basename $(strip $(shell \ - $(SED) -n -e '/^.*[^\]\{0,1\}%.*\\\(include\|input\)/!s/\\\(include\|input\)\(\[[^]]*\]\)\{0,1\}{[^}]*}/&\n/p' $< | \ - $(SED) -e 's/.*{\([^}]*\)}.*/\1/')))) - -# \includegraphicså½ä»¤ã§èªã¿è¾¼ã¾ããã°ã©ãã£ãã¯ãã¡ã¤ã« -ingraphics = $(strip $(shell \ - $(SED) -n -e '/^.*[^\]\{0,1\}%.*\\includegraphics/!s/\\includegraphics\(\[[^]]*\]\)\{0,1\}\({[^}]*}\)/&\n/p' $< $(intex) | \ - $(SED) -e 's/.*{\([^}]*\)}.*/\1/')) - # ä¾åé¢ä¿ã.dãã¡ã¤ã«ã«æ¸ãåºã %.d: %.tex - @$(ECHO) '$@ is created by scanning $^.' + @$(ECHO) '$@ is created by scanning $<.' # .dãã¡ã¤ã«ã®ä¾åé¢ä¿ @$(ECHO) '$(BASE).d: $(BASE).tex' >$@ # ä¸éãã¡ã¤ã«ã®ä¾åé¢ä¿ $(if $(INTERFILES),@( \ - $(ECHO); \ - $(ECHO) '# LaTeX Intermediate Files'; \ - $(ECHO) '$(BASE).dvi:: $(INTERFILES_PREV)'; \ - $(ECHO) ' @$$(COMPILE.tex)'; \ - $(ECHO); \ - $(ECHO) '$(BASE).dvi:: $(BASE).aux'; \ - $(ECHO) ' @$$(COMPILES.tex)'; \ - ) >>$@) + $(ECHO); \ + $(ECHO) '# LaTeX Intermediate Files'; \ + $(ECHO) '$(BASE).dvi:: $(INTERFILES_PREV)'; \ + $(ECHO) ' @$$(COMPILE.tex)'; \ + $(ECHO); \ + $(ECHO) '$(BASE).dvi:: $(BASE).aux'; \ + $(ECHO) ' @$$(COMPILES.tex)'; \ + ) >>$@) # ç»åãã¡ã¤ã«ã®ä¾åé¢ä¿ $(if $(ingraphics),@( \ + $(ECHO); \ + $(ECHO) '# IncludeGraphic Files - .pdf, .eps, .jpeg/.jpg, .png'; \ + $(ECHO) '# .xbb Files - .pdf, .jpeg/.jpg, .png'; \ + $(ECHO) '$(BASE).aux: $(ingraphics)'; \ + $(if $(filter-out %.eps,$(ingraphics)), \ $(ECHO); \ - $(ECHO) '# IncludeGraphic Files - .pdf, .eps, .jpeg/.jpg, .png'; \ - $(ECHO) '# .xbb Files - .pdf, .jpeg/.jpg, .png'; \ - $(ECHO) '$(BASE).aux: $(ingraphics)'; \ - $(if $(filter-out %.eps,$(ingraphics)), \ - $(ECHO); \ - $(ECHO) '$(BASE).aux: $(addsuffix .xbb,$(basename $(filter-out %.eps,$(ingraphics))))'; \ - ) \ - ) >>$@) -# \includeã¾ãã¯\inputå½ä»¤ã§èªã¿è¾¼ã¾ããTeXãã¡ã¤ã«ã®ä¾åé¢ä¿ + $(ECHO) '$(BASE).aux: $(addsuffix .xbb,$(basename $(filter-out %.eps,$(ingraphics))))'; \ + ) \ + ) >>$@) $(if $(intex),@( \ - $(ECHO); \ - $(ECHO) '# Files called from \include or \input - .tex'; \ - $(ECHO) '$(BASE).aux: $(intex)'; \ - ) >>$@) + $(ECHO); \ + $(ECHO) '# Files called from \include or \input - .tex'; \ + $(ECHO) '$(BASE).aux: $(intex)'; \ + ) >>$@) # æç®å¦çç¨ãã¡ã¤ã«ã®ä¾åé¢ä¿ $(if $(bibdb),@( \ - $(ECHO); \ - $(ECHO) '# Bibliography files: .aux, BIBDB -> .bbl -> .div'; \ - $(ECHO) '$(BASE).bbl: $(bibdb) $(BASE).tex'; \ + $(ECHO); \ + $(ECHO) '# Bibliography files: .aux, BIBDB -> .bbl -> .div'; \ + $(ECHO) '$(BASE).bbl: $(bibdb) $(BASE).tex'; \ ) >>$@) # 夿°TEXTARGETSã§æå®ãããã¿ã¼ã²ãããã¡ã¤ã«ã«å¯¾å¿ãã -- 2.18.0