TeX typesetting

1 readers
1 users here now

A place to share ideas, resources, tips, and hacks for Donald Knuths typesetting software TeX. All variants and formats like OpTeX, LaTeX and ConTeXt are welcome.

Tagging your post with [] is optional, but can help others to know if it uses or pertains to a certain format/engine/system.

Rules: Posts and comments should be civil and somehow related to *TeX and/or typesetting in general.

founded 1 year ago
MODERATORS
1
 
 

This is the sample code (for LuaTeX or XeTeX):

\documentclass{scrartcl}

\usepackage{pdfcomment}
\usepackage[english]{babel}
%\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{microtype}
\usepackage[svgnames,rgb]{xcolor}
\usepackage[absolute]{textpos}
\usepackage{amssymb,amsmath,array,bm}
\usepackage{courier}
\usepackage{calligra,mathptmx,helvet,concmath}
\usepackage{times}
\usepackage{fontspec} % used to access system fonts like Lucida Fax

\begin{document}

\defineavatar{standard}{height=10mm,width=15cm,type=freetext,color=white,fontsize=20pt,fontcolor=blue}%,voffset=-4.8cm,hoffset=-3.2cm}%

\noindent%
Fonts from the pdfcomment example document:\\[10mm]
\pdffreetextcomment[avatar=standard]{This font is Helvetica (the default)}\\[6mm]
\pdffreetextcomment[avatar=standard,font=LucidaConsole]{This font is LucidaConsole}\\[6mm]
\pdffreetextcomment[avatar=standard,font=Georgia]{This font is Georgia}\\[6mm]
\pdffreetextcomment[avatar=standard,font=PalatinoLinotype]{This font is PalatinoLinotype}\\[6mm]
Fonts considered among the ``14 standard fonts'':\\[10mm]
\pdffreetextcomment[avatar=standard,font=TiRo]{This font is Times-Roman (TiRo)}\\[6mm]
\pdffreetextcomment[avatar=standard,font=Helv]{This font is Helvetica (Helv)}\\[6mm]
\pdffreetextcomment[avatar=standard,font=Cour]{This font is Courier (Cour)}\\[6mm]
\pdffreetextcomment[avatar=standard,font=ZaDb]{This font is ZapfDingbats (ZaDb)}\\[6mm]
\pdffreetextcomment[avatar=standard,font=Symb]{This font is Symbol (Symb)}\\[6mm]
Ad-hoc selection:\\[10mm]
\pdffreetextcomment[avatar=standard,font=lmodern]{This font is Latin Modern}\\[6mm]
\pdffreetextcomment[avatar=standard,font=textcomp]{This font is textcomp}\\[6mm]
\pdffreetextcomment[avatar=standard,font=bogus]{This font is bogus (non-existent yet accepted!)}\\[6mm]
\pdffreetextcomment[avatar=standard,font={Lucida Fax}]{This font is Lucida Fax from fontspec}\\[6mm]
\pdffreetextcomment[avatar=standard,font=calligra]{This font is Calligra}\\[6mm]

\end{document}

The first question is what can be done to make the fonts render correctly in Poppler-based PDF viewers?

The other question: is Poppler the only game in the FOSS town? Or is there a FOSS alternative?

#askfedi #latex

2
 
 

OpTeX Tips and tricks section was updated with a macro that automatically makes sure that margin notes don't overlap. It's otherwise a problem when the margin notes are too close.

If you want to do it manually you can use \mnoteskip, but this is an automatic way.

3
 
 

Orphans and widows. On this subject Tschichold wrote:

"Doubtless all textbooks of typesetting warn that the exit line of a paragraph at the head of a book page must be avoided at all cost. /.../ Is there really nothing we can tighten a little, or space out perhaps? Possibly we can save a line at the beginning of the chapter by moving the first paragraph up? The best method is to simply shorten the preceding page by a line."

Bringhurst wrote:

"Balance facing pages not by adding extra lead or puffing up the word space, but by exporting or importing single lines to and from the preceding or following spreads. The same technique is used to avoid widows, and to extend or shorten any chapters that would otherwise end with a meager few lines on the final page."

In TeX we can set \widowpenalty (and \clubpenalty) to 10000 and if we have vertically stretchable material on the page the type area will get it's height, but lines will not match across the spread. Without strechable material that page will be a line shorter but the spread will be unbalanced in height instead.

So if we want this hands-on method of dealing with widows, we need a macro to carefully extend or shorten pages, preferably without being too intrusive and spread out in the code.

Luckily, Petr Olsak has a macro like this for OpTeX: https://petr.olsak.net/optex/optex-tricks.html#widows

For my purposes, I like the page number to be at a set distance from the type area instead of a set distance from the page bottom, so I could remove some code, and ended up with this example for plain:

% For this example, the document normally has 5 lines per page
\vsize=\topskip \advance\vsize by 4\baselineskip

% Backup original vsize 
\newdimen\originalvsize \originalvsize=\vsize

% Macro that defines another macro on the form \ap:<pageno>, 
% which expands to how many lines should be adjusted.
% Example: \adjustpage{15}{+1} defines \ap:15 which expands to +1.
\def\adjustpage#1#2{%
	\expandafter\xdef\csname ap:#1\endcsname{#2}
	\ifnum #1=1
		\setvsize
	\fi
}

% For use in the output routine
\def\setvsize{%
	\global\vsize=\originalvsize
	\ifcsname ap:\the\pageno\endcsname
		\global\advance \vsize by \csname ap:\the\pageno\endcsname \baselineskip
	\fi
}

% \setvsize needs to be expanded after page number has been incremented, but before the next typeset material.
\output{\plainoutput \setvsize}

%%%%%%%%%%%%%%%%%%%

% No penalty since we're dealing with widows manually now
\widowpenalty=0
\clubpenalty=0

% This adjusts the 2-3 spread to have one extra line on each page
\adjustpage{2}{+1} \adjustpage{3}{+1}

% Test text, some paragraphs of Lorem ipsum
\input lipsum

\bye
4
 
 

What's your method for dealing with underfull/overfull \hboxes and unacceptable badness in general?

LaTeX has the \sloppy command which IIRC sets \tolerance to 9999, and \emergencystretch to a large value. But the default \tolerance is 200 (I think), which is a big difference. It's very "either/or" when maybe there's a more optimal way.

For my native language (swedish) I've found that many issues arise because TeX doesn't find all the possible hyphenation points, so I usually spend time adding words to the hyphenation list.

But still, in any longer text there's usually a couple of paragraphs that just won't set right, I'm curious about your tricks or methods for dealing with them.

5
 
 

This is a rather interesting presentation by Jean-Luc Doumont about placing content on a grid, or a subset of the grid. He's kind of taking this idea to the extreme.

6
 
 

There's this guy called Stephan V. Bechtolsheim who wrote a series of books on TeX called "TeX in Practice". He's really good at the finer details of, well, everything.

In one of the books, he makes a macro to visualize boxes. It's built up over many pages and chapters with lots of small macros as building blocks. Because he's reusing these macros in different places, it makes a lot of sense.

However, when I wanted to use the box visualizing macro, I found that I had to look up and copy a lot of code to make it work. This was no fun, so I re-wrote it in a "flatter" way where it's just regular plain old macros.

I ended up with this:

\newdimen\linethickness \linethickness=0.4pt

\def\boxlines #1{%
    \hbox{%
        % Save original (argument) box
        \setbox0 = #1%
        % Place bullet at baseline and vertical align of the box
        \setbox1 = \hbox{\hskip -2.5pt \lower 2.5pt \hbox{$\circ$}}%
        \ht1=0pt \dp1=0pt \wd1=0pt
        \box1
        % Place a dashed line at baseline
        \setbox2 = \hbox to \wd0{%
            \xleaders\hbox to 4pt{%
                \hskip 1pt
                \vrule depth 0.5\linethickness 
                	   height 0.5\linethickness 
                	   width 2pt
                \hfil
            }%
            \hfil
        }%
        \ht2=0pt \dp2=0pt \wd2=0pt 
        \box2
        % Place frame
        \setbox 3 = \hbox{%         
            \hskip -0.5\linethickness
            \vrule width \linethickness height \ht0 depth \dp0% 
            \hskip \wd0% 
            \hskip -\linethickness
            \vrule width \linethickness height \ht0 depth \dp0% 
            \hskip -\wd0% 
            \hskip -\linethickness
            \dimen0 = \wd0% 
            \advance\dimen0 by \linethickness
            \dimen2 = \ht0% 
            \advance\dimen2 by 0.5\linethickness
            \dimen4 = \ht0% 
            \advance\dimen4 by -0.5\linethickness
            \dimen4 = -\dimen4
            \vrule width \dimen0 height \dimen2 depth \dimen4
            \hskip -\dimen0
            \dimen2 = \dp0% 
            \advance\dimen2 by -0.5\linethickness
            \dimen2 = -\dimen2
            \dimen4 = \dp0% 
            \advance\dimen4 by 0.5\linethickness
            \vrule width \dimen0 height \dimen2 depth \dimen4
        }%
        \ht3=0pt \dp3=0pt \wd3=0pt 
        \box3
        % Place original argument box
        \box0
    }%
}

The macro takes a box as an argument, for example \boxlines{\box0}

It puts lines around the box, and marks out the baseline and the horizontal alignment. The neat thing is that the lines are made so that they don't interfere with the typesetting at all. Everything is placed as it would be without the lines.

If you have something that looks misaligned or strange, like these words:

it can help to visualize the boxes:

7
1
submitted 1 year ago* (last edited 1 year ago) by quat@lemmy.sdfeu.org to c/tex@lemmy.sdfeu.org
 
 

Jan Tschichold and Raul Rosariva independently researched the layout of medieval books, and each came up with a method of construction. Rosarivas version (to the right) lends itself very well to a programmatic approach. We could implement it (in luaTeX) in a few lines like this:

% Page size (proportions 2:3)
\pagewidth=150mm	
\pageheight=225mm

% Undo 1 inch origin (personal preference)
\pdfvariable horigin 0pt
\pdfvariable vorigin 0pt

% Inner margin
\hoffset=\pagewidth
\divide\hoffset by9

% Top margin
\voffset=\pageheight
\divide\voffset by9

% Type area width
\hsize=\pagewidth
\divide\hsize by9
\multiply\hsize by6

% Type area height
\vsize=\pageheight
\divide\vsize by9
\multiply\vsize by6

This is all well and good if we have vertically stretchable material on every page. But... if we want to do grid typesetting, we will quickly run into "Underfull \vbox (badness 10000)".

Let's say we've set \parskip=0pt.

\topskip=10pt and \baselineskip=12pt

\showthe\vsize produced "426.79129pt" in the log.

Right now we have 35 lines: \topskip + 34 \baselineskips, which is 10pt+(34*12pt) = 418pt, i.e. less than \vsize, but there's no room for adding another line.

Something has got to give.

One way is to define \vsize as a set number of lines, and then adjust \baselineskip to be slightly bigger to make \vsize be in accordance with the golden canon.

Either we stay with 35 lines and increase \baselineskip slightly, or we decrease \baselineskip to fit one more line. This is where you have to make a call based on what would make it better as a whole. In this case, I think it wouldn't hurt with a little extra leading, so I'll stick with 1+34 lines and go back and change \vsize:

\vsize=\topskip
\advance\vsize by 34\baselineskip

Now all that is left is to figure out how much to increase \baselineskip. We can leave \topskip as it is, at 10pt, so we're left with 426.79129pt - 10pt = 416.79129pt.

Divide that with 34 lines:

416.79129pt / 34 is approximately 12.2586pt, so we go back and set \baselineskip to that.

\baselineskip=12.2586pt

Now we have something like this (with added guidelines):

Finally, if our goal here is to make a type area rectangle of a certain proportion, it could be argued that the first line should have its x-height touch the upper border of the rectangle. The bulk of a line contributing to color is made up of the lower case letters. In that case we could adjust \voffset:

\advance\voffset by-\topskip
\advance\voffset by 1ex

but then we would also have to compensate the total \vsize and figure out a new \baselineskip.

Disclaimer: I haven't tested the above code, so there could be spelling errors etc, but it's more about the reasoning.