# Breakable underline, no messing with line breaking

Chinese words aren't separated by spaces. As a result, neighboring underlines will be joined together. The xeCJK package provides a CJKunderline- command, but the underline it generates is unsymmetrical (the left end is often too short) and not directly customizable.

An alternative solution was provided in an old Chinese post. The underline looks nice, but unfortunately interferes with line breaking:

\documentclass[a4paper, 10pt]{article}

\usepackage{xcolor, indentfirst}
\usepackage[
left=3.2cm, right=3.2cm,
top=3.8cm, bottom=3.8cm,
]{geometry}

\usepackage[quiet]{fontspec}
\usepackage{xeCJK}
\setCJKmainfont{SimSun}

\setlength{\parindent}{2em}
\renewcommand{\baselinestretch}{1.3}

\usepackage[normalem]{ulem}

% How to make \myuline not mess with line breaking?
\newcommand{\basiculine}{\bgroup\markoverwith{\textcolor{gray}{\rule[-0.32em]{1pt}{0.54pt}}}\ULon}
\newcommand{\myuline}[1]{\hskip0.1em\basiculine{\kern-0.1em\hbox{#1\kern-0.1em}}\hskip0.1em}

\begin{document}

\end{document}


The first line's last underline pushes punctuation marks to the beginning of the next line. I'm not at all familiar with TeX constructs. How to improve this, please?

TeX is always allowed to break a line at an \hskip, unless explicitly told not to:

\documentclass[a4paper, 10pt]{article}

\usepackage{xcolor, indentfirst}
\usepackage[
left=3.2cm, right=3.2cm,
top=3.8cm, bottom=3.8cm,
]{geometry}

\usepackage[quiet]{fontspec}
\usepackage{xeCJK}
\setCJKmainfont{SimSun}

\setlength{\parindent}{2em}
\renewcommand{\baselinestretch}{1.3}

\usepackage[normalem]{ulem}

% How to make \myuline not mess with line breaking?
\newcommand{\basiculine}{%
\bgroup\markoverwith{\textcolor{gray}{\rule[-0.32em]{1pt}{0.54pt}}}\ULon
}
\newcommand{\myuline}[1]{%
\hspace{0.1em}%
\basiculine{\kern-0.1em\hbox{#1\kern-0.1em}}%
\nobreak % <----- no line break before the space
\hspace{0.1em}%
}

\begin{document}

\end{document}