I use Makefile and GNU make to create various output goals for a document based on the Markdown source file.
This includes using latex or pdflatex to create a DVI file. Using images in formats other than EPS or PS causes errors.
I can search and replace image names in the original markdown file and did it.
What I need to do is create a make file rule for all image files in the images/ subdirectory and run convert to create versions of these files.
So:
images/myimage1.png images/myimage2.jpeg
Saved, but additional versions created:
images/myimage1.eps images/myimage2.eps
(And yes, I have to make sure there are no name conflicts in other places.)
The command to run will look something like this:
convert -format eps images/myimage1.png images/myimage1.eps
I would like to run this in any image files other than EPS: gif, jpg, jpeg, png, bmp, etc. They will be specifically specified in the Makefile.
And here is the first iteration
It works (modulo other errors), although it is a little long, and if it is extended to all 193 image formats supported by Imagemagick, it will be ... unweildy.
My goal here is to create DVI, so I show related goals
dvi: docfs-Manifesto.dvi latex: docfs-Manifesto.tex epsimg.md: docfs-Manifesto.md docfs-Manifesto.tex: docfs-Manifesto-epsimg.md all-img pandoc -s --from=markdown --to=latex -o docfs-Manifesto.tex docfs-Manifesto-epsimg.md docfs-Manifesto-epsimg.md: docfs-Manifesto.md ./img-ref-to-eps.sed docfs-Manifesto.md > docfs-Manifesto-epsimg.md docfs-Manifesto.dvi: latex pdflatex -output-format dvi -halt-on-error docfs-Manifesto.tex 2>pdflatex.log MG_DIR=images EPS_DIR=images-eps # We can handle any of about 193 formats Imagemagick will read, but # let start with some basics # ... Source formats SRC_GIF = $(wildcard $(IMG_DIR)/*.gif) SRC_JPG = $(wildcard $(IMG_DIR)/*.jpg) # ... Destination formats EPS_GIF = $(patsubst $(IMG_DIR)/%.gif,$(EPS_DIR)/%.eps,$(SRC_GIF)) EPS_JPG = $(patsubst $(IMG_DIR)/%.jpg,$(EPS_DIR)/%.eps,$(SRC_JPG)) # And the actual conversions. This ... could be shorter? all-img: $(EPS_DIR) $(EPS_GIF) $(EPS_JPG) @echo "Done" $(EPS_DIR) : mkdir $(EPS_DIR) $(EPS_DIR)/%.eps : $(IMG_DIR)/%.gif convert -format eps $< $@ $(EPS_DIR)/%.eps : $(IMG_DIR)/%.jpg convert -format eps $< $@
(I think all the relevant rules)
And this succeeds since it fails with the image of my conversion script failed to convert.
But this is not a mistake.
Now handling code length with foreach loop
And we did it! 77 lines of code reduced to 17 (including spaces).
IMG_DIR=images EPS_DIR=images-eps
Current output (after make clean ):
$ make all-img convert -format eps images/browser-of-a-scientist.jpg images-eps/browser-of-a-scientist_jpg.eps convert -format eps images/nukewaste.jpg images-eps/nukewaste_jpg.eps convert -format eps images/standards.png images-eps/standards_png.eps $ ls images-eps/ browser-of-a-scientist_jpg.eps standards_png.eps nukewaste_jpg.eps