5

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}
\addtokomafont{disposition}{\frakfamily\fraklines}

\usepackage[hidelinks]{hyperref}

\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?

1 Answer 1

7

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

\documentclass[a4paper]{scrartcl}

\usepackage{yfonts}

\usepackage[hidelinks]{hyperref}



\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
\addtokomafont{sectioning}{\frakfamily}

\begin{document}

\frakfamily

\tableofcontents

\mySection{Jus:t a tes:t}

\end{document}
2
  • 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.
    – epR8GaYuh
    Commented Sep 7, 2018 at 5:23
  • yes, sorry I forgot the s in the regex. Commented Sep 7, 2018 at 7:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .