[Tex/LaTex] How to fix kerning of comma/colon after quotes

csquoteskerningpandocpunctuation

How to fix kerning of comma/colon after quotes?

Hello, I’m a relative newbie in latex and am trying to reduce the space between closing quotes and colon/comma, but by a general way in the preamble, not by manual \kern commands.

My document is actually in Portuguese, where it’s common to keep punctuation after the quotes (unlike English). Also, it is written in Markdown and translated into Latex by Pandoc; so it has a lot of \enquote followed by \autocite commands, which may be followed by colons/commas. Since I’m using biblatex’s footnote style, these cases are also problematic.

In the next sample, my current situation is in line 1, but want it to look more like lines 2 or 3.

\documentclass{article}
\usepackage[autocite=footnote]{biblatex}
\begin{document}
1) \enquote{something}\autocite{key}, or \enquote{something}.
2) \enquote{something}\kern-.3em,\autocite{key} or \enquote{something}\kern-.3em.
3) \enquote{something\makebox[0pt][l]{,}}\autocite{key} or \enquote{something\makebox[0pt][l]{.}}
\end{document}

Resulting image

Since Pandoc substitutes all quotes in my source file with \enquote commands, maybe a patch to it could do (but I dunno if it can deal with the interposed \autocite).

I'm using pdflatex as processor.

Best Answer

In this question it is shown how xetex and luatex can adjust font kerning automatically. I didn't test xetex's method, but this luatex code works like a charm:

\directlua{
local function kern_fix(fontdata)
 local ch = fontdata.characters[8221]
 ch.kerns = ch.kerns or {}
 ch.kerns[44] = -200000
 ch.kerns[46] = -200000
end
luatexbase.add_to_callback("luaotfload.patch_font", kern_fix, "kern_fix")
}

But since I want to stick with pdflatex my current solution is to use a perl script. This is my current makefile:

define PATCH
#remove italics in titles
if($$_ =~ /^#/) { $$_ =~ s/\*//g; }
#switch puncts and cites, but not inside footnotes
if($$_ !~ /^\[\^/) { $$_ =~ s/\s*(\[[^[^]*@[^[^]*\])([:punct:])/\2\1/g; }
#set old style numbers
$$_ =~ s/(\d+)/\\oldstylenums{\1}/g;
#insert kern between quotes and commas/colons
$$_ =~ s/’\s*([.,])/’\\kern-.15em\1/g;
$$_ =~ s/”\s*([.,])/”\\kern-.25em\1/g;
print $$_;
endef
export PATCH

all: neumann.pdf

view: neumann.pdf
    open neumann.pdf

clean:
    rm -f neumann.{aux,bbl,bcf,blg,fls,fdb*,log,toc,out,pdf,dvi,run*,syn*,tex}

neumann.pdf: neumann.tex neumann.bib
    latexmk -quiet -pdf neumann

neumann.tex: template.tex neumann.md
    perl -ne "$$PATCH" neumann.md | pandoc --template=template.tex --bibliography=neumann.bib --biblatex -o neumann.tex
Related Question