Here is a small bag of tips and tricks that I use to improve the handling and presentation of images in publications, which I want to share with you.
Use non-floating images
Most people think that the only way to insert an image in a publication is by using the LaTeX environment \begin{figure}...\end{figure}
. This has many advantages but also many disadvantages. Inserting images directly into the text i.e., by using the macro \includegraphics[]{}
gives you full control, but also full responsibility for the layout.
Enclose them in minipages
It is better to use an approach similar to HTML/CSS and use divs to enclose these, except these boxes are now minipages. You can the resize them to suit the layout as well as move them in any direction using vskip and hskip or the LaTeX equivalent of hspace and vspace. All the page layouts shown here were achieved using such an approach.
Use \newgeometry
and \restoregeometry
.
Sometimes it is much easier to adjust a layout by simply using the geometry package's new commands, \newgeometry and \restoregeometry.
Create a TeX Database
Another useful technique is to store all the images in a TeX database. This is not as complicated as it sounds. Remember that any macro actually can be used to store information. What I do is something resembling the following:
Create variations of commands using \csname..endcsname
holding the data for each image.
\mypics@img1@caption
\mypics@img1@longdescription
\mypics@img1@date
These are created automatically via a command \addtoDB{}{}{}
or similar. This also adds the original name into a list, which acts as the index.
\mypictures{img1,img2,img3,img4}
This enable easy use of multiple images, in a @for
loop. This is how the images above were inserted. The techniques can be used for almost everything, for example see some of the code at Cunning (La)TeX tricks and Adding a list of bios to the book class.
Keep the main file code to a minimal by leverage the filecontents package.
While developing pages, if you write everything in one file the code becomes bloated and confusing. What I do is to develop the page, first in the main file and then to use filecontents
to write it to the file. I then delete the relevant section and use \input
to load it onto the main file. I find it easier than opening and closing too many windows. I also use this to develop small packages, have the code first in the preamble, test as you go and when I am happy delete the filecontents
. An example of how to use this can be found at
internationalization. In What is a good strategy to internationalize a document class?, I used this technique to create a package-on-the-fly for whoever was to use the MWE.
Captions
Use a bit of innovation for these layouts see for example the images below which have a three column caption. (I use the caption
package for numbering).
I am currently incorporating all these into a class. Unfortunately the code is too lengthy to post here and also the class is not in a shape that I would feel comfortable to upload it to ctan
yet. With LaTeX's 3 coffins, I think I can also leverage the layouts a bit more and publish it sometimes over the next few months.
In the meantime if you need any help to incorporate these suggestions with what you are busy with, post a question and I can extract some of the code to help you out.
Not only for Modern books
The last example is from mathematics, from Newton's Principia. The left figure below shows my attempt using LaTeX and a bit of modern approach. The image on the right below is a scan of the original page. This was achieved using wrapfig
and a minimum of manual adjustment, just a negative vskip
a few points up to position the image better.
All the tools are here, go and make great books. thanks for reading this far.
There a few antialiasing artefacts that I don't know how to get rid of, and it uses some experimental code (what else?!). The font used is Hoefler (according to my Mac). The code itself won't work without some extra bits and pieces (one of which is the conversion of the Hoefler font to PGF paths - does anyone know the licence for Hoefler?). I also don't think that the braces are Hoefler.
For what it's worth, here's the code:
\documentclass{standalone}
%\url{http://tex.stackexchange.com/q/85050/86}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{shapes.letters,shadows.blur}
\pgfkeys{
/pgf/letter/.cd,
load font={hoefler}{normal},
size=4,
load encoding=name,
}
\definecolor{logoBack}{HTML}{F8F8F2}
\definecolor{brace}{HTML}{F6F6EF}
\definecolor{letter}{HTML}{C04848}
\makeatletter
\tikzset{
use letter path/.code={%
\pgfscope
\pgftransformscale{\letter@size}%
\letter@path{\letter@encode{#1}}%
\endpgfscope
}
}
\makeatother
\begin{document}
\begin{tikzpicture}[every shadow/.style={
shadow blur invert,
shadow xshift=-1pt,
shadow yshift=-3pt
}]
\coordinate (bleft) at (-2,0);
\coordinate (T) at (0,0);
\coordinate (E) at (2.3cm,-.65cm);
\coordinate (X) at (4.35cm,0);
\coordinate (bright) at (8.6,0);
\begin{scope}
\begin{scope}[shift={(bleft)}]
\fill[color=brace,use letter path=braceleft];
\clip[use letter path=braceleft];
\path[blur shadow,shadow xshift=2pt, shadow yshift=0pt,use letter path=braceleft];
\path[blur shadow,shadow xshift=-1pt, shadow yshift=0pt,use letter path=braceleft];
\end{scope}
\begin{scope}[shift={(T)}]
\fill[color=letter,use letter path=T];
\clip[use letter path=T];
\path[blur shadow,use letter path=T];
\end{scope}
\begin{scope}[shift={(E)}]
\fill[color=letter,use letter path=E];
\clip[use letter path=E];
\path[blur shadow,use letter path=E];
\end{scope}
\begin{scope}[shift={(X)}]
\fill[color=letter,use letter path=X];
\clip[use letter path=X];
\path[blur shadow,use letter path=X];
\end{scope}
\begin{scope}[shift={(bright)}]
\fill[color=brace,use letter path=braceright];
\clip[use letter path=braceright];
\path[blur shadow,shadow xshift=2pt, shadow yshift=0pt,use letter path=braceright];
\path[blur shadow,shadow xshift=-1pt, shadow yshift=0pt,use letter path=braceright];
\end{scope}
\path (current bounding box.north west) ++(-1,1) (current bounding box.south east) ++(1,-1);
\clip[shift={(T)},use letter path=T] (current bounding box.north west) rectangle (current bounding box.south east);
\clip[shift={(bleft)},use letter path=braceleft] (current bounding box.north west) rectangle (current bounding box.south east);
\clip[shift={(E)},use letter path=E] (current bounding box.north west) rectangle (current bounding box.south east);
\clip[shift={(X)},use letter path=X] (current bounding box.north west) rectangle (current bounding box.south east);
\clip[shift={(bright)},use letter path=braceright] (current bounding box.north west) rectangle (current bounding box.south east);
\fill[logoBack,rounded corners] (current bounding box.north west) rectangle (current bounding box.south east);
\end{scope}
\end{tikzpicture}
\end{document}
As well as needing the letter shapes from Hoefler and the code to make use of it, in doing this I spotted an issue with the pgf-blur library now needing unique fading names. So it really isn't compilable with "off the shelf" code! Modulo a few updates, most of it is on the TeX-SX launchpad - Hoefler being the key exception.
Best Answer
Add to their
aux
file the following code snippet, which is a quine. When theaux
file is\input
at the start of a LaTeX run, the code here will build a copy of itself and write it in theaux
file for the next run. Additionally, it will run the code contained in\toks2
below. For instance, the code I chose increases the indent size at each paragraph, but only if TeX is run on an odd minute: results depend on when your friend compiles.After one run, the
aux
file will contain the following condensed version (in a single line)and subsequent runs will leave the same condensed version (again in one line).
Let's see what happens in detail: within a (simple) group, the token register
\toks@
is set to some value, then its contents are used. What do those contents do? There is a test to check whether we are reading the aux file at the start or at the end of the run:\@nodocument
is\relax
in the second case and we do nothing. Then the toks register\toks2
is set to the code you actually want to perform. The following\edef\x{...}\x
construction expands the...
tothen performs that code.
\AtBeginDocument
will run its argument a bit later, once LaTeX is again ready to write in theaux
file (currently it is reading it). So, once LaTeX is ready to write to theaux
file, it performs your code (which was stored temporarily in\toks2
), then stores the<contents of \toks@>
back into\toks@
(this token register may have been used by other code in between), and writes the following to theaux
file (remember that\write
expands):This is precisely the original code, which thus ends up in the
aux
file for the next run of LaTeX.Hopefully, the code I chose to put in
\toks2
is easy enough to follow:if the time (in minutes since the beginning of the day) is an odd number, then at every paragraph, do whatever was already done at every paragraph, and also advance (increase) the paragraph indentation (
\parindent
) by 2 points. For instance, say you add the first or second code snippets above to theaux
file generated by runningpdflatex
on the document below. Then the document will be normal if compiled on an even minute, and otherwise will have ever growing paragraph indentation.