[XeTeX] Code review

Clinton Gormley clint at traveljury.com
Fri Jan 8 15:46:23 CET 2010


Hi all

I've got my first LATEX file assembled and working, and I'm hoping for
some feedback about how to improve what I've done, and to make it less
fragile and repetitive.

The goal is to build a system to allow users to book newspaper adverts
online, where each advert will be a single PDF that gets sent to the
newspaper.

Different newspapers will have different font, spacing and column
dimensions, so I should be able to load a 'style' file for the relevant
advert.

For demo purposes, I've combined the base package, the style file and
the content template into a single .tex file:

http://hacks.traveljury.com/test.tex  (also included below)

and it produces this PDF:

http://hacks.traveljury.com/test.pdf

Questions:
----------
1) Is my use of \fontspec and  \fontsize correct? I seem to 
   be repeating myself a lot - any way I can make this less
   repetitive?

2) I'm using a bounding box from tikz to put a border around
   the notice, but there was quite a bit of padding between
   the border and the contained content, until I set
   negative values for 'inner xsep' and 'inner ysep'.
   Unfortunately, these values, plus the values for hmargin
   need to change if the font-size changes.  Any way to
   make this more robust?

3) Some of the numbers are shifted down (eg see "7lb 8oz")
   Is this the font, or a LATEX effect?  Is there anyway I 
   can prevent this from happening?

Thanks in advance for any feedback.

Clint

test.tex:
---------

%%%% THIS SECTION TO BE STORED IN A PACKAGE %%%%
\documentclass{article}
\usepackage{fontspec}
\usepackage{xunicode}
\usepackage{xltxtra}
\usepackage{geometry}
\usepackage{tikz}
\usetikzlibrary{backgrounds}

\pagestyle{empty}
\setlength{\parindent}{0ex}
\sloppy

\newcommand{\IAtitle}[1]{
    \par{\IAtitlefont\selectfont{#1\par}}
}
\newcommand{\IAsubtitle}[1]{
    \par{\IAsubtitlefont\selectfont{#1\par}}
}

\newcommand{\IAcontentbox}[1]{
    \newbox\contents
    \savebox\contents{%
        \begin{tikzpicture}
             [
                background rectangle/.style={thick,draw=black,rounded
corners},
                show background rectangle
            ]
            \node[
                use as bounding box,
                inner xsep=-2pt, 
                inner ysep=-10pt, 
                outer sep=0pt
            ]{\parbox{\linewidth}{
                \setlength{\parskip}{3pt minus 3pt}
                #1
            }};
        \end{tikzpicture}
    }
    \pdfpageheight=\dimexpr\dp\contents+\ht\contents
    \noindent\makebox[\linewidth]{\usebox\contents}
}
%%%% END PACKAGE FILE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% THESE STYLES TO BE SET IN A SEPARATE STYLE FILE %%%%
\newcommand{\IAtitlefont}{
    \fontspec[Mapping=tex-text]{Frutiger Linotype Bold}\fontsize{16}{16}
}

\newcommand{\IAsubtitlefont}{
    \fontspec[Mapping=tex-text]{Frutiger Linotype Bold}\fontsize{12}{14}
}

\newcommand{\IAbasefont}{
    \fontspec[Mapping=tex-text]{Frutiger Linotype}\fontsize{8}{10}
}

\geometry{
    paperwidth=32mm,
    vmargin=0pt,
    hmargin={4pt,1pt}
}
%%%% END OF STYLE FILE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% START CONTENT FILE %%%%%

\begin{document}
    \IAcontentbox{
        \begin{center}
            \IAbasefont\selectfont   
            \IAtitle{ SMITH-BLOGGS}
            \IAsubtitle{ ALEX and MARIANNE}

            Are pleased to announce the safe arrival of
            \IAsubtitle{Lionel Richard} 
            their first baby, on November 13th
            November weighing 7lb 8oz, a little brother for Michael, 
            Fred, Daisy \& Lucy. Thanks to the staff of Main 
            Delivery Suit \& Special Care unit \& Ward 11 at WPH.

            Thank you for the safe arrival of Lionel Richard. Mum you 
            did `really well' she's really gorgeous, we couldn't 
            be more proud. 

            Lots of Love from Bob, Fred and Jane
        \end{center}
    }%
\end{document}
%%%% END CONTENT FILE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%





More information about the XeTeX mailing list