Alternative to detokenize working with special unicode characters
It's a bit more complicated than using \detokenize
, particularly with IL2
. By the way, do you really need it?
Here's a way that preprocesses the input so to change _<>
into proper commands.
\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[slovak]{babel}
\usepackage{nameref}
\usepackage{xparse}
\usepackage[hidelinks,breaklinks]{hyperref}
\ExplSyntaxOn
\NewDocumentCommand\mynode{mmmm}
{
\mynode_main:nnnn { #1 } { #2 } { #3 } { #4 }
}
\seq_new:N \l_mynode_input_seq
\seq_new:N \l_mynode_output_seq
\tl_new:N \l_mynode_node_tl
\tl_new:N \l_mynode_text_tl
\cs_new_protected:Nn \mynode_main:nnnn
{
\seq_set_split:Nnn \l_mynode_input_seq { ; } { #3 }
\seq_set_split:Nnn \l_mynode_output_seq { ; } { #4 }
\tl_set:Nn \l_mynode_node_tl { #1 }
\mynode_replace:N \l_mynode_node_tl
\tl_set:Nn \l_mynode_text_tl { #2 }
\mynode_replace:N \l_mynode_text_tl
\mynode_paragraph:VV \l_mynode_node_tl \l_mynode_text_tl
\label{ \tl_to_str:n { #1 } }
\begin{itemize}
\item vstupné~hrany:~
\seq_map_variable:NNn \l_mynode_input_seq \l_mynode_node_tl
{
\mynode_print:N \l_mynode_node_tl
}
\item výstupné~hrany:~
\seq_map_variable:NNn \l_mynode_output_seq \l_mynode_node_tl
{
\mynode_print:N \l_mynode_node_tl
}
\end{itemize}
}
\cs_new_protected:Nn \mynode_paragraph:nn
{
\paragraph[#1]{#2~(\texttt{#1}):}
}
\cs_generate_variant:Nn \mynode_paragraph:nn { VV }
\cs_new_protected:Nn \mynode_print:N
{
\texttt
{
\tl_if_empty:NTF #1
{ - }
{ \nameref { \tl_to_str:N #1 } }
};~
}
\cs_new_protected:Nn \mynode_replace:N
{
\regex_replace_all:nnN { \_ } { \c{_} } #1
\regex_replace_all:nnN { \< } { \c{textless} } #1
\regex_replace_all:nnN { \> } { \c{textgreater} } #1
}
\NewDocumentCommand{\change}{m}
{
\tl_set:Nn \l_mynode_text_tl { #1 }
\mynode_replace:N \l_mynode_text_tl
\tl_use:N \l_mynode_text_tl
%\tl_analysis_show:N #1 %%% for debugging
}
\ExplSyntaxOff
\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}{}
\mynode{<test>}{Some text with \texttt{under_score}}{<test>}{}
\end{document}