Printing books and such in color can be expensive. So here is how to count the color pages using a recent version of GhostScript and a UNIX shell:
gs -o - -sDEVICE=inkcov input.pdf | grep -v "^ 0.00000 0.00000 0.00000" | grep "^ " | wc -l
A collection of coding snippets, tips, hints and random thoughts.
Printing books and such in color can be expensive. So here is how to count the color pages using a recent version of GhostScript and a UNIX shell:
gs -o - -sDEVICE=inkcov input.pdf | grep -v "^ 0.00000 0.00000 0.00000" | grep "^ " | wc -l
Very neat thing indeed: It seems one can precompile the LaTeX preamble, to speed up LaTeX runs. Useful for repeated LaTeX runs, or for generating large amounts of similar LaTeX documents.
The other day I was using the moderncv document class to create a CV. I also added my publications to the CV, which was supposed to be in German. BibTeX created a section “Literatur” for this. Obviously, I wanted the title of the bibliography to be “Publikationen” instead. When using the german package of babel, you can change the bibliography title like this in the LaTeX preamble:
addtocaptionsgerman{renewcommand{refname}{Publikationen}}
I just opened an old TeX file, which was still encoded in latin1. Now I wanted to re-save it as utf-8 in Emacs. This turns out to be very simple, as someone on #emacs at freenode told me. Just hit C-x RET f, and type utf-8 RET. On the next save (C-x C-s), the file will be written as utf-8.
As a reminder to myself: On the TeX Stackexchange, there is a nice question and discussion by me and some helpful people on how to use LaTeX code in gnuplot / how to embed LaTeX equations in a plot. A copy of my revised answer:
First, we set up a gnuplot called test.plt:
plot [-5:5] [-1.5:1.5] sin(x+pi) title "$\sin(x+\pi)$"
Then we also set up a small Makefile:
.SUFFIXES: .plt .tex .pdf
%.tex: %.plt
gnuplot -e "
set format '$%g$' ;
set terminal epslatex standalone color ;
set output '$@'
" $<
%.pdf: %.tex
pdflatex $<
all: test.pdf
Running “make all” will produce this plot:
I wanted to make a Makefile for a seminar report. This report contains all the sub-reports of the students. So the Makefile needs to recurse into subdirectories to compile all the contained LaTeX files there. So, given a file reports.tex which will include some PDFs in subdirectories 00/ to 10/, we get a Makefile that looks like this:
#####################################################
# A small LaTeX Makefile
#####################################################
PREFIX=reports
CHAPTERS=00 01 02 03 04 05 06 07 08 09 10
all: subdirs $(PREFIX).pdf
#####################################################
.PHONY: subdirs simple
subdirs:
@for i in $(CHAPTERS); do
(cd $$i; $(MAKE)); done
#####################################################
$(PREFIX).aux: $(PREFIX).tex
pdflatex $(PREFIX).tex
$(PREFIX).pdf: $(PREFIX).aux
pdflatex $(PREFIX).tex
#####################################################
simple:
pdflatex $(PREFIX).tex
#####################################################
clean:
@for i in $(CHAPTERS); do
(cd $$i; $(MAKE) clean); done
rm -f $(PREFIX).aux $(PREFIX).bbl $(PREFIX).blg
$(PREFIX).idx $(PREFIX).log $(PREFIX).out $(PREFIX).tcp
$(PREFIX).toc $(PREFIX).tps $(PREFIX).prf $(PREFIX).lbl
rm -f $(PDFFILES) *.aux