SHELL = /bin/sh # Requires img-ref-to-eps.sed script posted separately. # Replace this with the basename of your file, w/o the extension. E.g., "myfile.md" => "myfile". DOC_NAME := Your Document Name Here DOC_DATE := $(shell date +'%B %d, %Y') # Utilities # ... change to suite. PANDOC = /usr/local/bin/pandoc PDFLATEX = /Library/TeX/texbin/pdflatex PDFTOPS = /usr/local/bin/pdftops # ... We prefer GNU tar. For Homebrew / OSX: TAR = /usr/local/bin/tar W3M = /usr/local/bin/w3m # For later PANDOC_OPTIONS = --toc --reference-location=section --top-level-division=chapter --number-sections -V date='$(DOC_DATE)' --pdf-engine=xelatex PANDOC_BEAMER_OPTIONS = --reference-location=section --top-level-division=chapter --number-sections --incremental --pdf-engine=xelatex PANDOC_HTML_OPTIONS = --ascii --reference-location=block --css=standard.css PANDOC_STUB_HTML_OPTIONS = --reference-location=section --top-level-division=section --ascii --reference-location=block MARKDOWN_EXTENSIONS = +autolink_bare_uris+ascii_identifiers LATEX_OPTIONS = -V "colorlinks=true, linkcolor=1E6B8C, links-as-notes=true, lof=true, lot=true" .SUFFIXES: .SUFFIXES: .md .pdf .epub .djvu .fb2 .ps .html .txt .info .orgmode .dvi .asciidoc .textile .rtf .opendoc .odt .docx .mediawiki .PHONY: clean print openpdf openpub openhtml htmltar-clean # NB: djvu not supported. all: pdf epub djvu fb2 ps stub-html html latex txt info orgmode dvi asciidoc textile rtf opendoc odt docx mediawiki # excluded: beamer: breaks build primary: pdf epub fb2 ps html txt secondary: latex beamer stub-html info orgmode dvi asciidoc textile rtf opendoc mediawiki tertiary: djvu odt docx beamer install: @echo "This is not implemented" false uninstall: @echo "This is not implemented" false # Quickview openpdf: pdf open $(DOC_NAME).pdf openepub: epub open $(DOC_NAME).epub openhtml: html open $(DOC_NAME).html openps: ps open $(DOC_NAME).ps opentxt: txt open $(DOC_NAME).txt # Formats. Think about these # ... Primary outputs pdf: $(DOC_NAME).pdf epub: $(DOC_NAME).epub fb2: $(DOC_NAME).fb2 ps: $(DOC_NAME).ps html: $(DOC_NAME).html txt: $(DOC_NAME).txt # ... Secondary otuputs latex: $(DOC_NAME).tex beamer: $(DOC_NAME)-beamer.pdf stub-html: $(DOC_NAME)-stub.html info: $(DOC_NAME).info orgmode: $(DOC_NAME).org dvi: $(DOC_NAME).dvi asciidoc: $(DOC_NAME).asciidoc textile: $(DOC_NAME).textile rtf: $(DOC_NAME).rtf opendoc: $(DOC_NAME).opendoc mediawiki: $(DOC_NAME).mediawiki # ... Tertiary Outputs # See note at $(DOC_NAME).djvu target # djvu: $(DOC_NAME).djvu djvu: @echo "DjVu is not supported" true odt: $(DOC_NAME).odt docx: $(DOC_NAME).docx htmltar: $(DOC_NAME)-html.tar.gz htmltar-clean @echo "htmltar" # Utility outputs # Swap any image file formats for eps epsimg: $(DOC_NAME)-epsimg.md $(DOC_NAME)-epsimg.md: $(DOC_NAME).md ./img-ref-to-eps.sed $(DOC_NAME).md > $(DOC_NAME)-epsimg.md # For real making $(DOC_NAME).pdf: $(DOC_NAME).md $(PANDOC) $(PANDOC_OPTIONS) $(LATEX_OPTIONS) --from=markdown$(MARKDOWN_EXTENSIONS) --to=latex -o $(DOC_NAME).pdf $(DOC_NAME).md $(DOC_NAME).epub: $(DOC_NAME).md $(PANDOC) $(PANDOC_OPTIONS) --from=markdown$(MARKDOWN_EXTENSIONS) --to=epub -o $(DOC_NAME).epub $(DOC_NAME).md # Mon Dec 18 04:44:11 UTC 2017 # See, generally: https://commons.wikimedia.org/wiki/Help:Creating_a_DjVu_file # # I've chased a few leads trying to get a DjVu generator. No dice. # - djvudigital needs a licence-incompatible Ghostscript driver. Which # fails to build under OSX. # - pdf2djvu is another package. It's available for Debian, and on # Github, but not in Homebrew. Github source fails with a UTF8.h # error. That seems to be under poppler .. # - poppler, also on Github, also fails to build on OSX. # # That being attempted, I'm going to abandon DjVu as an endpoint for now, # but leave this note as to why. # - dredmorbius #$(DOC_NAME).djvu: pdf $(DOC_NAME).md # true $(DOC_NAME).fb2: $(DOC_NAME).md $(PANDOC) $(PANDOC_OPTIONS) --from=markdown$(MARKDOWN_EXTENSIONS) --to=fb2 -o $(DOC_NAME).fb2 $(DOC_NAME).md $(DOC_NAME).ps: pdf $(DOC_NAME).md $(PDFTOPS) $(DOC_NAME).pdf $(DOC_NAME).ps $(DOC_NAME).html: $(DOC_NAME).md $(PANDOC) --standalone --ascii $(PANDOC_OPTIONS) $(PANDOC_HTML_OPTIONS) --from=markdown$(MARKDOWN_EXTENSIONS) --to=html -o $(DOC_NAME).html $(DOC_NAME).md $(DOC_NAME)-stub.html: $(DOC_NAME).md $(PANDOC) --ascii $(PANDOC_STUB_HTML_OPTIONS) --from=markdown$(MARKDOWN_EXTENSIONS) --to=html -o $(DOC_NAME)-stub.html $(DOC_NAME).md $(DOC_NAME).txt: html $(DOC_NAME).md $(W3M) -dump -cols 80 $(DOC_NAME).html > $(DOC_NAME).txt $(DOC_NAME).tex: epsimg all-img $(DOC_NAME).md $(PANDOC) --standalone $(PANDOC_OPTIONS) $(LATEX_OPTIONS) --from=markdown$(MARKDOWN_EXTENSIONS) --to=latex -o $(DOC_NAME).tex $(DOC_NAME)-epsimg.md $(DOC_NAME)-beamer.pdf: epsimg all-img $(DOC_NAME).md @echo "beamer: not implemented" true $(PANDOC) --standalone $(PANDOC_BEAMER_OPTIONS) --from=markdown$(MARKDOWN_EXTENSIONS) --to=beamer -o $(DOC_NAME)-beamer.pdf $(DOC_NAME).md $(DOC_NAME).info: $(DOC_NAME).md $(PANDOC) $(PANDOC_OPTIONS) --from=markdown$(MARKDOWN_EXTENSIONS) --to=texinfo -o $(DOC_NAME).info $(DOC_NAME).md $(DOC_NAME).org: $(DOC_NAME).md $(PANDOC) --standalone --from=markdown$(MARKDOWN_EXTENSIONS) --to=org -o $(DOC_NAME).org $(DOC_NAME).md $(DOC_NAME).dvi: latex $(DOC_NAME).md # Yes, twice. Thanks, LaTeX.... $(PDFLATEX) $(LATEX_OPTIONS) -output-format dvi -halt-on-error $(DOC_NAME).tex 2>pdflatex.log $(PDFLATEX) $(LATEX_OPTIONS) -output-format dvi -halt-on-error $(DOC_NAME).tex 2>pdflatex.log $(DOC_NAME).asciidoc: $(DOC_NAME).md $(PANDOC) --from=markdown$(MARKDOWN_EXTENSIONS) --to=asciidoc -o $(DOC_NAME).asciidoc $(DOC_NAME).md $(DOC_NAME).textile: $(DOC_NAME).md $(PANDOC) --from=markdown$(MARKDOWN_EXTENSIONS) --to=textile -o $(DOC_NAME).textile $(DOC_NAME).md $(DOC_NAME).rtf: $(DOC_NAME).md $(PANDOC) $(PANDOC_OPTIONS) --from=markdown$(MARKDOWN_EXTENSIONS) --to=rtf -o $(DOC_NAME).rtf $(DOC_NAME).md $(DOC_NAME).opendoc: $(DOC_NAME).md $(PANDOC) $(PANDOC_OPTIONS) --from=markdown$(MARKDOWN_EXTENSIONS) --to=opendocument -o $(DOC_NAME).opendoc $(DOC_NAME).md $(DOC_NAME).odt: $(DOC_NAME).md $(PANDOC) $(PANDOC_OPTIONS) --from=markdown$(MARKDOWN_EXTENSIONS) --to=odt -o $(DOC_NAME).odt $(DOC_NAME).md $(DOC_NAME).docx: $(DOC_NAME).md $(PANDOC) $(PANDOC_OPTIONS) --from=markdown$(MARKDOWN_EXTENSIONS) --to=docx -o $(DOC_NAME).docx $(DOC_NAME).md $(DOC_NAME).mediawiki: $(DOC_NAME).md $(PANDOC) --from=markdown$(MARKDOWN_EXTENSIONS) --to=mediawiki -o $(DOC_NAME).mediawiki $(DOC_NAME).md $(DOC_NAME)-html.tar.gz: $(DOC_NAME).html standard.css images @echo "$(DOC_NAME)-html.tar.gz" mkdir $(DOC_NAME)-html cd $(DOC_NAME)-html ln -s ../$(DOC_NAME).html $(DOC_NAME)-html/$(DOC_NAME).html ln -s ../standard.css $(DOC_NAME)-html/standard.css ln -s ../images $(DOC_NAME)-html/images cd .. $(TAR) --dereference -czvf $(DOC_NAME)-html.tar.gz $(DOC_NAME)-html/ --owner=-2 --group=-2 htmltar-clean: $(DOC_NAME)-html.tar.gz @echo "htmltar-clean" rm -rf $(DOC_NAME)-html # Images # ... We want to have EPS versions of any non-EPS files, for LaTeX # so ... convert all image files to eps. IMG_DIR=images EPS_DIR=images-eps # We can handle any of about 193 formats Imagemagick will read, but # let's start with some basics # Thanks @kebs: https://stackoverflow.com/a/47857821/9105048 IMG_EXT=bmp dot gif jpg jpeg png raw tiff xcf pnm ppm ps # ... Source formats IMG_FILES = $(wildcard $(IMG_DIR)/*) # Rename files s/./_/ so: img1.gif => img1_gif Then add extension IMG_FILES2 = $(subst .,_,$(IMG_FILES)) EPS_FILES = $(patsubst $(IMG_DIR)/%,$(EPS_DIR)/%.eps,$(IMG_FILES2)) all-img: $(EPS_DIR) $(EPS_FILES) @echo "all-img: done" $(EPS_DIR) : mkdir $(EPS_DIR) $(foreach \ prereq, \ $(IMG_EXT), \ $(eval $(EPS_DIR)/%_$(prereq).eps: $(IMG_DIR)/%.$(prereq); convert -format eps $$< $$@) \ ) # Debuggery print: @echo Variables DEBUG @echo SHELL: $(SHELL) @echo TAR: $(TAR) @echo DATE: $(DOC_DATE) @echo IMG_DIR: $(IMG_DIR) @echo EPS_DIR: $(EPS_DIR) @echo IMG_EXT: $(IMG_EXT) @echo IMG_FILES: $(IMG_FILES) @echo IMG_FILES2: $(IMG_FILES2) @echo EPS_FILES: $(EPS_FILES) # Your mother does not live here clean: rm -f $(DOC_NAME).pdf $(DOC_NAME).epub $(DOC_NAME).fb2 $(DOC_NAME).djvu $(DOC_NAME).ps $(DOC_NAME).html $(DOC_NAME)-stub.html $(DOC_NAME).txt $(DOC_NAME)-epsimg.md $(DOC_NAME).tex $(DOC_NAME)-beamer.pdf $(DOC_NAME).info $(DOC_NAME).org $(DOC_NAME).dvi $(DOC_NAME).asciidoc $(DOC_NAME).textile $(DOC_NAME).rtf $(DOC_NAME).opendoc $(DOC_NAME).odt $(DOC_NAME).docx $(DOC_NAME).mediawiki # Latex rm -f $(DOC_NAME).log $(DOC_NAME).aux $(DOC_NAME).out texput.log pdflatex.log $(DOC_NAME).toc # EPS rm -f $(EPS_FILES) rm -rf $(EPS_DIR) # html-tar rm -rf $(DOC_NAME)-html/ rm -f $(DOC_NAME)-html.tar.gz