Gatwood Publishing

Gatwood Publishing: LaTeX Tips

LaTeX Tips:

This page contains a collection of LaTeX tips used during book production.


Min-Width Box

Emulates the CSS min-width property in LaTeX. The min-height property is easy to emulate using a strut, but the min-width property requires some computation.

\usepackage{fp}


\newlength{\stringwidth}
\newsavebox\chapternumbox
\newlength\minboxwidth
\newlength\minboxwidthcounter


\makeatletter
\newcommand*{\getlength}[1]{\strip@pt#1}
\makeatother

\newcommand\hstrut[1]{\rule{#1}{0pt}}
\newcommand\minwidthbox[2]{%
        \savebox{\chapternumbox}{#2}%
        \settowidth{\stringwidth}{\usebox{\chapternumbox}}%
%
        \setlength\minboxwidth{#1}%
        \edef\minboxwidthcounter{\getlength{\minboxwidth}}%
        \edef\stringwidthcounter{\getlength{\stringwidth}}%
        \FPsub{\strutWidth}{\minboxwidthcounter}{\stringwidthcounter}%
%
        \ifdim \stringwidth<\minboxwidth {%
                \ifodd\count1\relax%
                \else\relax%
                        \hstrut{\strutWidth pt}\relax%
                \fi\relax%
        }%
        \fi\relax%
        \usebox{\chapternumbox}%
        \ifdim \stringwidth<\minboxwidth {%
                \ifodd\count1\relax%
                        \hstrut{\strutWidth pt}\relax%
                \else\relax%
                \fi\relax%
        }%
        \fi\relax%
}

Length to Point Count

Computes the number of points in an arbitrary length. There are other ways to do this, but sometimes they don't work well in complex macros.

\usepackage{fp}
\usepackage{xstring}


\newcounter{novelTempLen}
\newcounter{lengthToPointCountResult}


\newcommand{\lengthToPointCount}[1]{%
        \IfSubStr{#1}{in}{%
            % Inches
            \PackageWarning{novel_dblatex}{Converting from inches}%
%
            \StrDel{#1}{in}[\novelTempCount]%
            \FPmul{\thelengthToPointCountResult}{\novelTempCount}{72.27}%
        }{%
            \IfSubStr{#1}{cm}{%
                %% cm
                \PackageWarning{novel_dblatex}{Converting from cm}%
%
                \StrDel{#1}{cm}[\novelTempCount]%
                \FPmul{\thelengthToPointCountResult}{\novelTempCount}{28.4}%
            }{%
                \IfSubStr{#1}{mm}{%
                    %% mm
                    \PackageWarning{novel_dblatex}{Converting from mm}%
%
                    \StrDel{#1}{cm}[\novelTempCount]%
                    \FPmul{\thelengthToPointCountResult}{\novelTempCount}{2.84}%
                }\IfSubStr{#1}{pt}{%
                    % em, etc. are invalid in this context, so
                    % assume points.
%
                    \PackageWarning{novel_dblatex}{Converting from points}%
                    \StrDel{#1}{pt}[\novelTempCount]%
                    % \message{1 is #1 TC: }
                    % \show\novelTempCount
                    % \message{ done}
                    % \setcounter{lengthToPointCountResult}{\value{\novelTempCount}}
                    \FPmul{\thelengthToPointCountResult}{\novelTempCount}{1.00}%
                }{%
                    % em, etc. are invalid in this context, so
                    % assume points.
%
                    \PackageWarning{novel_dblatex}{Converting from points (guess)}%
                    % \message{1 is #1 TC: }
                    % \show\novelTempCount
                    % \message{ done}
                    \edef\temp{#1}%
    % \message{LTPC 1}
                    % \setcounter{lengthToPointCountResult}{\value{\novelTempCount}}
    % \message{LTPC 2}
                    \FPmul{\thelengthToPointCountResult}{\novelTempCount}{1.00}%
    % \message{LTPC 3}
                }%
            }%
        }%
}

% Example:
\setlength\novelPageHeight{11in}
\lengthToPointCount{\novelPageHeight}
\let \novelPageHeightInPoints\thelengthToPointCountResult

PDF/X-1a:2001 2001a Compliance

PDF-X compatibility requires you to specify a number of additional pieces of information above and beyond what is normally present in a PDF file. This snipped provides examples of those pieces of information.


% Ensure that whitespace between certain macros does not collapse.
\def\space{ }

\special{ pdf:put @catalog <<
        /OutputIntents [ <<
        /Info (none)
        /Type /OutputIntent
        /S /GTS_PDFX
        /OutputConditionIdentifier (lightningsource.com)
        /RegistryName (https://www.lightningsource.com/)>> ] >>}

\newcommand \addTrimBoxes {%
        \special{ pdf: put @thispage << /MediaBox [ 0 0 \novelPageWidthInPostScriptPoints\space \novelPageHeightInPostScriptPoints\space ] >>}
        \ifodd\count1%
                \special{ pdf: put @thispage << /TrimBox [ \novelInsideCropMarginInPostScriptPoints\space \novelBottomCropMarginInPostScriptPoints\space \novelPageWidthInPostScriptPoints\space \novelPageHeightInPostScriptPoints\space ] >>}
                \special{ pdf: put @thispage << /BleedBox [ \novelInsideCropMarginInPostScriptPoints\space \novelBottomCropMarginInPostScriptPoints\space \novelPageWidthInPostScriptPoints\space \novelPageHeightInPostScriptPoints\space ] >>}
        \else%
                \special{ pdf: put @thispage << /TrimBox [ 0 \novelBottomCropMarginInPostScriptPoints\space \novelLogicalPageWidthInPostScriptPoints\space  \novelPageHeightInPostScriptPoints\space ] >>}
                \special{ pdf: put @thispage << /BleedBox [ 0 \novelBottomCropMarginInPostScriptPoints\space \novelLogicalPageWidthInPostScriptPoints\space  \novelPageHeightInPostScriptPoints\space ] >>}
        \fi%
}

\AtBeginShipout{\addTrimBoxes}

Note: PostScript/PDF points and LaTeX points are not equal. PDF points are equal to LaTeX "big points" (the bp unit). To compute PostScript points, multiply the number of LaTeX points by 72, then divide by 72.27.