Context: In my document, I use a citation mechanism for personal references. I defined a \citeref{} macro that processes a comma-separated list of arguments. The latter have following structure: abc_123. The purpose of the \citeref macro
is to iterate over the list of arguments, do some black magic (not represented in the MWE), and finally print the list of arguments within squared brackets. Because there is an underscore in the references, I \detokenize them in order to typeset them.
Problem: The hyphenation of the abc_123-like references is not optimal. Notably, no line break is enabled after the underscore _. Yet using the hyphenat package is not effective, as the string is detokenized.
Question: How to enable line break/hyphenation after an underscore inside a detokenized string?
MWE
\documentclass[a5paper]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{etoolbox}
\newcommand{\citeref}[1]{
% cf. https://tex.stackexchange.com/a/87423/64454; https://tex.stackexchange.com/q/367418/64454
[%
\def\nextitem{\def\nextitem{, }}% Separator
\forcsvlist\citerefitem{#1}% Process list
]%
}
\newcommand{\citerefitem}[1]{%
\nextitem
\detokenize{#1}%
}
\usepackage{hyphenat}
\begin{document}
Usually, it works fine: either for single \dots\dots\dots\dots\citeref{abcabc_123} or for multiple references \dots\dots\dots\dots\citeref{abc_123, def_456}.
However, for longer references, a hyphenation would be welcome after the underscore: \citeref{abcdefghijklmnopqrstuvwxyz_12345678910111213}.
\end{document}


abc_123intoabc\_123: this would enable me to usehyphenatas is and not use\detokenize. However, I don't want this solution as my "black magic" notably consists in writing this reference into an external file for later processing. – ebosi Jul 16 '17 at 15:21etoolbox? – egreg Jul 16 '17 at 15:26(-;. – ebosi Jul 16 '17 at 15:28\immediate\write\tempfile{#1}. So I suppose any other way to process a comma-separated list would be ok. – ebosi Jul 16 '17 at 15:30\_the code substitutes something like\_\allowbreak– egreg Jul 16 '17 at 15:45\usepackage{hyphenat} + \_=\_\allowbreak. However, I would prefer not change myabc_123intoabc\_123(orabc\_\allowbreak 123), as I would like to have the stringabc_123to be written in my temporary file without backslash... – ebosi Jul 16 '17 at 15:54