I am trying to create a document which I can typeset either using the standard font or fraktur.

Consider the following MWE:

\documentclass[a4paper]{scrbook}

\usepackage[utf8]{inputenc}
\usepackage[german]{babel}

\usepackage{yfonts}

\begin{document}

\frakfamily

Test

Tes:t

This:: should have one colon.

Another example: The colon should stay here.

\end{document}

Typesetting it as-is, there is no problem. If I remove the \frakfamily command to typeset the document with the standard font, the colon used for customizing the fraktur output is displayed inside the output.

How to switch between fraktur and standard fonts on-the-fly? And is there a way to declare the usage of fraktures for all document content inside the preamble?

To clarify it a bit more: The document should be typeset either completely with fraktur or with the standard fonts. As I do not want to create two different source files, I was searching for a way to automatically suppress single colons after an s when using the standard fonts. (This would be easy when using an external script, but I would need another intermediate source file beside the existing one in this case.)

  • in the fractur font s: is a ligature. In pdflatex it is imho not possible to add such a ligature on the fly to a font. With xelatex or lualatex it could be possible. – Ulrike Fischer Aug 18 at 13:31
  • @UlrikeFischer If I understand your comment correctly, one would have to define the s: ligature in the used standard font to behave the same like s to solve the problem? If it is not possible with pdflatex, I might be able to switch the engine - while I prefer lualatex over xelatex. – epR8GaYuh Aug 18 at 13:45
  • If you are willing to switch engines, maybe this answer will help: tex.stackexchange.com/a/218326/87678 – David Purton Aug 18 at 14:24
up vote 6 down vote accepted

With pdflatex you could try something like this:

\documentclass[a4paper]{scrbook}

\usepackage[utf8]{inputenc}
\usepackage[german]{babel}

\usepackage{yfonts}

\sfcode`\s=1001
\catcode`\:=\active
\DeclareRobustCommand:{\ifnum\spacefactor=1001 \spacefactor=1000 \else \string:\fi}

\begin{document}

%\frakfamily

Test

Tes:t

This:: should have one colon.

Another example: The colon should stay here.

\end{document}

enter image description here

With lualatex you could do something like this:

\documentclass[a4paper]{scrbook}

\usepackage[german]{babel}
\usepackage{fontspec}
\directlua{
fonts.handlers.otf.addfeature({
    name = "ligc",
    type = "ligature",
    data = {
      ["s"] = { "s", ":" },
    }})}

\setmainfont{TeX Gyre Pagella}[RawFeature=+ligc]    
\begin{document}

Test

Tes:t

This:: should have one colon.

Another example: The colon should stay here.

\end{document}
  • Thanks, the lualatex solution works fine, while the pdflatex solution seems to fail with an Improper \spacefactor error when used within section headers (\section{Tes:t} for example). – epR8GaYuh Aug 18 at 14:31
  • 2
    Make the : robust: \DeclareRobustCommand: – Ulrike Fischer Aug 18 at 14:37

With help from this answer, here's a solution with xelatex:

Find on your system the file tex-text.map and copy it to your working directory under the name fraktur.map (or whatever you want). Then append to it a line so that it looks like:

; TECkit mapping for TeX input conventions <-> Unicode characters

LHSName "TeX-text"
RHSName "UNICODE"

pass(Unicode)

; ligatures from Knuth's original CMR fonts
U+002D U+002D           <>  U+2013  ; -- -> en dash
U+002D U+002D U+002D    <>  U+2014  ; --- -> em dash

U+0027          <>  U+2019  ; ' -> right single quote
U+0027 U+0027   <>  U+201D  ; '' -> right double quote
U+0022           >  U+201D  ; " -> right double quote

U+0060          <>  U+2018  ; ` -> left single quote
U+0060 U+0060   <>  U+201C  ; `` -> left double quote

U+0021 U+0060   <>  U+00A1  ; !` -> inverted exclam
U+003F U+0060   <>  U+00BF  ; ?` -> inverted question

; additions supported in T1 encoding
U+002C U+002C   <>  U+201E  ; ,, -> DOUBLE LOW-9 QUOTATION MARK
U+003C U+003C   <>  U+00AB  ; << -> LEFT POINTING GUILLEMET
U+003E U+003E   <>  U+00BB  ; >> -> RIGHT POINTING GUILLEMET

; additions to suppress fraktur ligature
U+0073 U+003A   <>  U+0073  ; s: -> LATIN SMALL LETTER S

Then run

teckit_compile fraktur.map

which will create a file named fraktur.tec.

Then, you can use this mapping file with xelatex like this:

\documentclass{article}
\usepackage[german]{babel}
\usepackage{fontspec}
\usepackage{yfonts}

\setmainfont{Latin Modern Roman}[Mapping=fraktur]

\begin{document}

Test

Tes:t

This:: should have one colon.

Another example: The colon should stay here.


\frakfamily

Test

Tes:t

This:: should have one colon.

Another example: The colon should stay here.

\end{document}

enter image description here

  • This does not seem to affect section titles, see \section{Tes:t} for example. – epR8GaYuh Aug 18 at 14:57
  • 1
    @epR8GaYuh you are using scrbook, which sets the section titles in sans serif, so you will have to add the mapping instruction also to the sans family with e.g. \setsansfont{Latin Modern Sans}[Mapping=fraktur] – Ulrike Fischer Aug 18 at 16:10

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.