-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Doc examples: compile through the makefile.
Previously, the compilation of individual examples was triggered by compilation of the documentation. This was cumbersome, and required shell escape mode. Changes: * The compilation is triggered through the Makefile in the examples folder. All targets are listed explicitly, and the number of compilations needed to produce an example is specified. * The resulting files are preprocessed where needed (no more `\sed`ding and inputting `.mmz` files during compilation). * In the document source, \ExampleName is abolished and \tcbinputexample has simpler argument structure. * Centralized extraction of excerpts.
- Loading branch information
1 parent
b82a3e9
commit e879ea4
Showing
12 changed files
with
395 additions
and
533 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ | |
!ins.end | ||
!memoize.cfg | ||
!*.gitignore | ||
!extract-excerpts.pl | ||
!get-filename-from-mmz.tex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,124 @@ | ||
SHELL := /bin/bash | ||
N = 1 | ||
.PHONY: clean all excerpts | ||
.SECONDARY: | ||
.DEFAULT_GOAL := all | ||
|
||
.PRECIOUS: %.c1 | ||
|
||
%.ins: ins.begin ins.mid ins.end | ||
sed 's|example|$*|g;' $< > $@ | ||
cat ins.begin > $@ | ||
for n in {1..$N} ; do sed "s|example|$*|g; s/c1/c$$n/g;" ins.mid >> $@ ; done | ||
cat ins.end >> $@ | ||
clean: | ||
find . \( \( -type f -not \( \ | ||
-name '*.dtx' -or -name 'ins.*' -or -name .gitignore -or \ | ||
-name Makefile -or -name memoize.cfg -or -name extract-excerpts.pl -or \ | ||
-name get-filename-from-mmz.tex | ||
\) \) -or \( -type d -name '*.memo.dir' \) \) -print -delete | ||
|
||
%.c1: %.dtx %.ins | ||
tex -interaction batchmode $*.ins | ||
sed -i 's/~//g;' $*.c? $*.c?.attachment | ||
echo $@ | ||
N = 0 | ||
|
||
%.pdf: %.tex.c1 | ||
cp $*.tex.c1 $*.tex | ||
%.pdf: %.tex | ||
touch $*.mmz ; memoize-clean.py --all --yes $*.mmz | ||
rm -f $*.mmz | ||
latexmk -C $* | ||
for n in {1..$N}; do cp $*.tex.c$$n $*.tex ; pdflatex -interaction batchmode $* ; cp $*.pdf $*.c$$n.pdf ; if [[ -a $*.mmz ]] ; then cp $*.mmz $*.mmz.c$$n ; fi ; done | ||
|
||
%.sty: %.sty.c1 | ||
cp $*.sty.c$N $@ | ||
if [[ $(N) > 0 ]] ; then \ | ||
for ((n=1;$$n<=$(N);n++)) ; do \ | ||
cp $*.tex.c$$n $*.tex ; \ | ||
pdflatex -interaction batchmode $* ; \ | ||
cp $*.pdf $*.c$$n.pdf ; \ | ||
if [[ -a $*.mmz ]] ; then cp $*.mmz $*.mmz.c$$n ; fi ; \ | ||
done ; \ | ||
else \ | ||
pdflatex -interaction batchmode $* ; \ | ||
fi | ||
|
||
%.excerpt: $(SOURCE) | ||
if [[ -z '$(SOURCE)' ]] ; then echo Empty SOURCE! ; false ; fi | ||
perl -e '$$f=q{$*}; while(<>) {$$r &&= !/^ *% *\\\Qend{listingregion}/; print if $$r; $$r ||= /^ *% *\\\Qbegin{listingregion}{$$f}/; }' ${SOURCE} > $@ | ||
%:: %.dtx | ||
sed 's|example|$*|g;' ins.begin > $*.ins | ||
for ((n=1;$$n<=$(N);n++)) ; \ | ||
do sed "s|example|$*|g; s/c1/c$$n/g;" ins.mid >> $*.ins ; \ | ||
done | ||
cat ins.end >> $*.ins | ||
tex -interaction batchmode $*.ins | ||
shopt -s nullglob ; sed -i 's/~//g;' $* $*.attachment $*.c? $*.c?.attachment | ||
|
||
%.listing.attachment: %.listing | ||
sed 's/~//g;' $< > $@ | ||
|
||
.PHONY: clean | ||
clean: | ||
find . -type f -not \( -name '*.dtx' -or -name 'ins.*' -or -name .gitignore -or -name Makefile \) -delete | ||
EMPTY :::= | ||
SPACE :::= $(EMPTY) $(EMPTY) | ||
SED_CMD :::= \\\\\([a-zA-Z]\\+\) | ||
SED_CMD_ :::= \\\\[a-zA-Z]\\+ | ||
SED_MARG :::= {\([^}]*\)} | ||
SED_MARG_ :::= {[^}]*} | ||
|
||
# returns the one and only mandatory argument of the first occurrence of \\$(1) in file $(2) | ||
FIRST_ARG = `grep $(1) $(2) | head -1 | sed 's/$(SED_CMD_) *$(SED_MARG)/\1/'` | ||
|
||
# returns the one and only mandatory argument of the second occurrence of \\$(1) in file $(2) | ||
SECOND_ARG = `grep $(1) $(2) | head -2 | tail -1 | sed 's/$(SED_CMD_) *$(SED_MARG)/\1/'` | ||
|
||
# returns the one and only mandatory argument of the last occurrence of \\$(1) in file $(2) | ||
LAST_ARG = `grep $(1) $(2) | tail -1 | sed 's/$(SED_CMD_) *$(SED_MARG)/\1/'` | ||
|
||
# GET_FILENAME_FROM_MMZ = etex -interaction batchmode '\input{get-filename-from-mmz}\get{$(1)}{$(2)}{$(3)}{$(4)}{$(5)}' | ||
GET_FILENAME_FROM_MMZ = etex '\input{get-filename-from-mmz}\get{$(1)}{$(2)}{$(3)}{$(4)}{$(5)}' | ||
|
||
excerpts: memoize.excerpts advice.excerpts collargs.excerpts | ||
|
||
%.excerpts: ../../%.edtx | ||
perl extract-excerpts.pl $< && touch $@ | ||
|
||
TARGETS = memoize-example.cfg disable-bad.tex disable-good.tex disable-nomemoize.tex disable-nommz.tex disable-auto-cmd.tex disable-auto-env.tex book.tex chapters/chapter1.tex memoize-region.cfg titlepage.pdf test.pdf manual.pdf mmztikz.pdf automemoize-environment.pdf automemoize-command.pdf recompile.pdf disable.pdf readonly.pdf meaning-to-context.pdf clean-house.pdf dirty-house.pdf beamer.pdf overlay.pdf verbatim-manual.pdf verbatim-auto.pdf capture.pdf no-linebreaking.pdf sectionbox.tex ref.pdf vref.tex fontsize.pdf skak.pdf redefinitions.pdf progressbar.pdf poormansbox.sty poormansbox.pdf poormansbox-memoizable.sty poormansbox-memoizable.pdf memoize-internal.pdf label.pdf label+.pdf per-overlay-v1.sty salt.pdf record-files.tex record-extern-pages.tex pgfmathparse.pdf pgfmathparse-embellished.pdf countdown.pdf countdown.sty poormansbox-driver.pdf poormansbox-driver.sty _auto-ref.tex chained-advice.tex om-collector-NewDocumentCommand.tex om-collector-newcommand.tex collargs-makebox.tex collargs-minipage.tex collargs-verbatim.tex plainTeX.tex ConTeXt.tex _collargs-verbatim.tex _collargs-ignore-other-tags.tex collargs-processor.tex collargs-expandable-processor.tex collargs-nodelimiters.tex collargs-return-plain.tex collargs-return-no.tex collargs-transition-ok.tex collargs-transition-cs.tex collargs-transition-comment.tex \ | ||
titlepage.mmz.c1 titlepage.mmz.c2 titlepage.cmemo titlepage.ccmemo poormansbox-memoizable.cmemo label.ccmemo label+.ccmemo ref.cmemo beamer.cmemo beamer.ccmemo poormansbox-driver.ccmemo pgfmathparse.ccmemo | ||
|
||
all: excerpts $(TARGETS) | ||
|
||
chained-advice.tex _collargs-ignore-other-tags.tex countdown.sty poormansbox-driver.pdf fontsize.pdf label+.pdf meaning-to-context.pdf memoize-internal.pdf no-linebreaking.pdf progressbar.pdf readonly.pdf titlepage.pdf : N = 2 | ||
label.pdf recompile.pdf : N = 3 | ||
overlay.pdf : N = 4 | ||
label+.tex redefinitions.pdf : N = 6 | ||
ref.pdf : N = 7 | ||
|
||
poormansbox.pdf: poormansbox.sty | ||
poormansbox-memoizable.pdf: poormansbox-memoizable.sty | ||
countdown.pdf: countdown.sty | ||
poormansbox-driver.pdf: poormansbox-driver.sty | ||
|
||
titlepage.mmz.c1: titlepage.pdf | ||
sed -i 's/\\mmzNewExtern/~\0~/' $@ | ||
|
||
titlepage.mmz.c2: titlepage.pdf | ||
sed -i 's/\\mmzUsedExtern/~\0~/' $@ | ||
|
||
titlepage.cmemo: titlepage.pdf | ||
$(call GET_FILENAME_FROM_MMZ,GetFirst,mmzNewCMemo,$(basename $<).mmz.c1,mymemo,$@) | ||
|
||
titlepage.ccmemo: titlepage.pdf | ||
$(call GET_FILENAME_FROM_MMZ,GetFirst,mmzNewCCMemo,$(basename $<).mmz.c1,mymemo,$@) | ||
sed 's/\\quitvmode \\mmzIncludeExtern/\\quitvmode\n\\mmzIncludeExtern/; s/\\\mmzStepPgfPictureId/\n\0/' `tail -1 titlepage.ccmemo` > $@.listing | ||
|
||
poormansbox-memoizable.cmemo: poormansbox-memoizable.pdf | ||
$(call GET_FILENAME_FROM_MMZ,GetLast,mmzNewCMemo,$(basename $<).mmz,mymemo,$@) | ||
sed 's/]{/]\n {/;' `tail -1 $@` > $@.listing | ||
|
||
label.ccmemo: label.pdf | ||
$(call GET_FILENAME_FROM_MMZ,GetFirst,mmzNewCCMemo,$(basename $<).mmz.c1,mymemo,$@) | ||
sed 's/\\quitvmode \\mmzIncludeExtern/\\quitvmode\n\\mmzIncludeExtern/; s/$(SED_MARG)\\mmzIncludeExtern/{\1}\n\\mmzIncludeExtern/; s/\\mmzLabel *$(SED_MARG)$(SED_MARG)/~\\mmzLabel{\1}{\2}~ /g; s/\\\mmzStepPgfPictureId/\n\0/; ' `tail -1 $@` > $@.listing | ||
|
||
label+.ccmemo: label+.pdf | ||
$(call GET_FILENAME_FROM_MMZ,GetFirst,mmzNewCCMemo,$(basename $<).mmz.c1,mymemo,$@) | ||
sed 's/\\mmzLabel *$(SED_MARG)$(SED_MARG)/~\0~/; s/$(SED_MARG)\\mmzIncludeExtern/\1 \\mmzIncludeExtern/; s/\($(SED_MARG_)$(SED_MARG_)$(SED_MARG_)\)\($(SED_MARG_)$(SED_MARG_)$(SED_MARG_)$(SED_MARG_)\)/\1 \2/;' `tail -1 $@` > $@.listing | ||
|
||
ref.cmemo: ref.pdf | ||
$(call GET_FILENAME_FROM_MMZ,GetFirst,mmzNewCMemo,$(basename $<).mmz.c1,mymemo,$@) | ||
sed 's/\\global.*/~\0~/' `tail -1 $@` > $@.listing | ||
|
||
beamer.cmemo: beamer.pdf | ||
$(call GET_FILENAME_FROM_MMZ,GetFirst,mmzNewCMemo,$(basename $<).mmz,mymemo,$@) | ||
sed 's/\\mmzSetBeamerOverlays $(SED_MARG)$(SED_MARG)/~\0~/' `tail -1 $@` > $@.listing | ||
|
||
beamer.ccmemo: beamer.pdf | ||
$(call GET_FILENAME_FROM_MMZ,GetFirst,mmzNewCCMemo,$(basename $<).mmz,mymemo,$@) | ||
sed 's/overlay=[0-9]*/~\0~/; s/pauses=[0-9]*/~\0~/; s/}\\mmzIncludeExtern/}\n\\mmzIncludeExtern/; s/\\\mmzStepPgfPictureId/\n\0/; ' `tail -1 $@` > $@.listing | ||
|
||
poormansbox-driver.ccmemo: poormansbox-driver.pdf | ||
$(call GET_FILENAME_FROM_MMZ,GetSecond,mmzNewCCMemo,$(basename $<).mmz.c1,mymemo,$@) | ||
sed 's/\\csuse *{poormansbox@outer}/~\0~/; s/{\\mmzIncludeExtern.*}}/~\0~/' `tail -1 $@` > $@.listing | ||
|
||
pgfmathparse.ccmemo: pgfmathparse.pdf | ||
$(call GET_FILENAME_FROM_MMZ,GetFirst,mmzNewCCMemo,$(basename $<).mmz,mymemo,$@) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
while (<>) { | ||
if ($in_listing) { | ||
if (/^ *% *\\end\{listingregion\}/) { | ||
# print the collected lines, automatically deindented | ||
$indent = -1; | ||
for my $line (@lines) { | ||
$line =~ /^ */; | ||
$current_indent = length($&); | ||
$indent = -1 ? $current_indent : min($indent, $current_indent); | ||
} | ||
for $line (@lines) { | ||
print LISTING substr($line, $indent); | ||
} | ||
# close the excerpt file | ||
close LISTING; | ||
$in_listing = 0; | ||
} else { | ||
# append to the list | ||
push(@lines, $_); | ||
} | ||
} elsif (/^ *% *\\begin\{listingregion\}\{([^}]*)\}/) { | ||
# upon encountering " % \begin{listingregion}{<filename>}", | ||
# open the excerpt file, initialize the excerpt list | ||
open LISTING, ">$1.excerpt"; | ||
$in_listing = 1; | ||
@lines = (); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
% execute with etex | ||
|
||
\def\mmzPrefix#1{} | ||
\def\mmzNewCMemo#1{} | ||
\def\mmzNewCCMemo#1{} | ||
\def\mmzNewExtern#1#2#3#4{}% | ||
\def\mmzUsedCMemo#1{} | ||
\def\mmzUsedCCMemo#1{} | ||
\def\mmzUsedExtern#1{} | ||
|
||
\def\GetFirst#1{% | ||
\def\filename{#1}% | ||
\endinput | ||
} | ||
\def\GetSecond#1{% | ||
\def\GetSecond##1{% | ||
\def\filename{##1}% | ||
\endinput | ||
}% | ||
} | ||
\def\GetLast#1{% | ||
\def\filename{#1}% | ||
} | ||
|
||
% #1 = GetFirst | GetSecond | GetLast | ||
% #2 = mmzNewCMemo | mmzNewCCMemo | ... (mmzNewExtern is not supported) | ||
% #3 = from <filename.mmz> | ||
% #4 = store into this cs (in TeX output) | ||
% #5 = into thi filename (plus .tex for TeX output) | ||
\def\get#1#2#3#4#5{% | ||
\expandafter\edef\csname#2\endcsname{% | ||
\unexpanded\expandafter{\csname#1\endcsname}% | ||
}% | ||
\input{#3}% | ||
\immediate\openout0{#5}% | ||
\immediate\immediate\write0{% | ||
\noexpand\def\unexpanded\expandafter{\csname#4\endcsname}{\filename}}% | ||
\immediate\immediate\write0{\noexpand\endinput}% | ||
\immediate\immediate\write0{\filename}% | ||
\immediate\closeout0 | ||
\csname bye\endcsname | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.