# Replace ligature in bookmarks

I am trying to replace the s: ligature in the bookmarks by just an s. This is needed as my document is written using a fraktur font, but the colon appears inside the bookmarks as they are not in fraktur.

My current code is the following one:

\documentclass[a4paper]{scrartcl}

\usepackage{yfonts}

\usepackage{xstring}
\newcommand{\removeLigatures}[1]{%
\IfSubStr{#1}{s:}{%
\StrSubstitute{#1}{s:}{s}%
}{#1}
}

\newcommand{\mySection}[1]{%
\section{\texorpdfstring{#1}{\removeLigatures{#1}}}
}

\begin{document}

\frakfamily

\tableofcontents

\mySection{Jus:t a tes:t}

\end{document}


There seems to be some issue with my code, as I get a bookmark with the text Jus:t a tes:ts:s:sJus:t a tes:t. How can I fix this to achieve the desired results?

You must do the replacement before feeding the argument to \texorpdfstring. E.g. with expl3:

\documentclass[a4paper]{scrartcl}

\usepackage{yfonts}

\usepackage{expl3}
\ExplSyntaxOn
\newcommand\removeLigatures[1]{%
\tl_set:Nn \l_tmpa_tl{#1}
\regex_replace_all:nnN { s: } { s } \l_tmpa_tl
}
\newcommand{\mySection}[1]{%
\removeLigatures{#1}
\section{\texorpdfstring{#1}{\l_tmpa_tl}}
}

\ExplSyntaxOff

• While this works for the basic case, this eliminates all colons from s::, too. Instead this should be translated to s: as inside the document text itself (where it is represented by the s: ligature followed by a regular colon). This seems to be just a little regex fix. Sep 7 '18 at 5:23