I have defined new command using \NewDocumentCommand
which represents description of node in graph. This contains name (provided as argument), some text description (provided as argument) and links to other nodes (specified as semicolon separated list of names in argument). From answer to this question, I have discovered \detokenize
command, which allows me to properly display node names containing underscores. (Also I use this in \paragraph
names, \label
names and \ref
erences.)
Problem is, when I use \detokenize
on text description, some Unicode characters are replaced with wrong characters. (For example, softvér
gets replaced by softvŠr
.) Is there some alternative to \detokenize
? I only need to automatically escape <
and >
that are present in some descriptions. I could use \textless
and textgreater
, but I had to use detokenize
for names (so that referencing would work, I could not escape it properly as it is argument of macro), so I would like to have some consistency and provide description un-escaped.
edit here is small example:
\documentclass[12pt, oneside]{book}
\usepackage[a4paper,top=2.5cm,bottom=2.5cm,left=3.5cm,right=2cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[IL2]{fontenc}
\usepackage[hidelinks,breaklinks]{hyperref}
\usepackage[slovak]{babel}
\usepackage{nameref}
\usepackage{xparse}
\usepackage{ifthen}
\linespread{1.25}
\NewDocumentCommand\mynode{mm>{\SplitList{;}}m>{\SplitList{;}}m}
{
\paragraph[\detokenize{#1}]{\detokenize{#2} (\texttt{\detokenize{#1}}):}
\label{\detokenize{#1}}
\begin{itemize}
\item vstupné hrany:
\ProcessList{#3}{ \insertdep }
\item výstupné hrany:
\ProcessList{#4}{ \insertdep }
\end{itemize}
}
\newcommand{\insertdep}[1]{
\ifthenelse{\equal{}{#1}}{\texttt{-}}{\texttt{\nameref{\detokenize{#1}}};}
}
\begin{document}
\mynode{root}{Koreň}{root}{gui}
\mynode{gui}{Grafické rozhranie}{root}{nice_gui;fancy_gui}
\mynode{nice_gui}{Pekné grafické rozhranie}{gui}{}
\mynode{fancy_gui}{This text contains less and greater characters:<>}{gui}{}
\end{document}
\detokenize{#2}
breaks special Slovak characters (compared to using only #2
). I have noticed, that it does not even fix problems with _<>
. I have noticed, that when I use \verb|#2|
instead of \detokenize{#2}
, Slovak characters and <>
work, but it obviously changes formatting and for some reason adds |
at the end of text, and underscores still make latex to insert math mode and make subscript.
I'm using pdflatex
to compile.
_
,<
and>
in label names without needing to do anything,\label{foo_bar}
...\ref{foo_bar}
works. – David Carlisle Apr 21 '19 at 12:41usepackage
commands. Sorry if some are left. – user224348 Apr 21 '19 at 13:49\detokenize
completely disables latex's encoding support. – David Carlisle Apr 21 '19 at 14:53