1

Problem:

If there is no punctuation in the text, the Chinese words could be aligned perfectly vertically, however, if I add punctuation, somehow the punctuation will be mis-alighed, for example enter image description here Compiled with XeLatex, code:

%!TeX program = XeLaTeX
\documentclass{article}

\documentclass{article}
\usepackage{xeCJK}
\setCJKmainfont{Noto Sans CJK TC}
\usepackage[overlap,CJK]{ruby}
\usepackage{setspace}
\usepackage{geometry}
\usepackage{parskip}

% Margin Settings
\geometry{
a4paper,
total={170mm,257mm},
left=25mm,
right=25mm,
top=30mm,
bottom=20mm
}

% Chinese Pinyin Setttings
\renewcommand\rubysep{-3em}
\renewcommand{\CJKglue}{\hskip 14}
\renewcommand\rubysize{0.6}
\let\oldruby\ruby
\def\ruby#1#2{\oldruby{#1}{#2}\futurelet\next\addCJKglue}
\def\addCJKglue{\ifx\next\ruby \CJKglue \fi}
\newcommand{\myruby}[2]{\renewcommand\rubysep{-3em}{\chn\ruby{#1}{\textsf{#2}}}}

\newenvironment{chineseenvcustom}[2][2]
  {
   \begin{spacing}{#1}
   \huge \justifying\renewcommand{\CJKglue}{\hskip #2}} 
  {\end{spacing}}


\begin{document}
\begin{chineseenvcustom}{12}
\ruby{彌}{Mí}\ruby{勒}{Lè}\ruby{世}{Shì}\ruby{尊}{Zūn}~\ruby{,}{}\ruby{既}{Jì}\ruby{慈}{Cí}\ruby{隆}{Lóng}\ruby{即}{Jí}\ruby{世}{Shì}~\ruby{,}{}\ruby{悲}{Bēi}\ruby{臻}{Zhēn}\ruby{後}{Hòu}\ruby{劫}{Jié}~\ruby{,}{}\ruby{依}{Yī}\ruby{事}{Shì}\ruby{題}{Tí}\ruby{名}{Míng}\ruby{弗}{Fú}\ruby{敢}{Gǎn}\ruby{移}{Yí}\ruby{易}{Yì}~\ruby{.}{}\ruby{承}{Chéng}\ruby{此}{Cǐ}\ruby{念}{Niàn}\ruby{力}{Lì}~\ruby{,}{}\ruby{欲}{Yù}\ruby{守}{Shǒu}\ruby{護}{Hù}\ruby{三}{Sān}\ruby{寶}{Bǎo}~\ruby{,}{}\ruby{令}{Lìng}\ruby{魔}{Mó}\ruby{隱}{Yǐn}\ruby{蔽}{Bì}~\ruby{.}{}\ruby{摧}{Cūi}\ruby{伏}{Fú}\ruby{自}{Zì}\ruby{大}{Dà}\ruby{增}{Zēng}\ruby{上}{Shàng}\ruby{慢}{Màn}\ruby{者}{Zhě}~\ruby{,}{}\ruby{未}{Wèi}\ruby{種}{Zhòng}\ruby{善}{Shàn}\ruby{根}{Gēn}\ruby{者}{Zhě}~\ruby{,}{}\ruby{今}{Jīn}\ruby{當}{Dāng}\ruby{令}{Lìng}\ruby{種}{Zhòng}~\ruby{.}{}\ruby{已}{Yǐ}\ruby{種}{Zhòng}\ruby{善}{Shàn}\ruby{根}{Gēn}\ruby{者}{Zhě}~\ruby{,}{}\ruby{今}{Jīn}\ruby{令}{Lìng}\ruby{增}{Zēng}\ruby{長}{Zhǎng}~\ruby{.}{}\ruby{若}{Ruò}\ruby{計}{Jì}\ruby{有}{Yǒu}\ruby{所}{Suǒ}\ruby{得}{Dé}~\ruby{,}{}\ruby{住}{Zhù}\ruby{諸}{Zhū}\ruby{見}{Jiàn}\ruby{者}{Zhě}~\ruby{,}{}\ruby{皆}{Jiē}\ruby{悉}{Xī}\ruby{令}{Lìng}\ruby{發}{Fā}\ruby{捨}{Shě}\ruby{離}{Lí}\ruby{之}{Zhī}\ruby{心}{Xīn}~\ruby{.}{}\ruby{樂}{Lè}\ruby{小}{Xiǎo}\ruby{法}{Fǎ}\ruby{者}{Zhě}~\ruby{,}{}\ruby{令}{Lìng}\ruby{不}{Bù}\ruby{疑}{Yí}\ruby{大}{Dà}\ruby{法}{Fǎ}~\ruby{.}{}\ruby{樂}{Lè}\ruby{大}{Dà}\ruby{法}{Fǎ}\ruby{者}{Zhě}~\ruby{,}{}\ruby{令}{Lìng}\ruby{生}{Shēng}\ruby{歡}{Huān}\ruby{喜}{Xǐ}~\ruby{.}{}
\end{chineseenvcustom}

\end{document}

Question:

Is it possible to let punctuation doesn't take space, for example, put it in the right corner of the previous character, therefore, the non-punctuation Chinese character could still get aligned.

Reference:

The same quesiton: Is there a punctuation mark that does not take up any space?. But since I am using rudy to add pinyin to the Chinese characters, the method suggested there is not working anymore.

Any help is appreciated, thank you in advance :)

4

You can add a special helper \punct, which is used instead of ruby for punctuation marks. This stops \futurelet from detecting ruby and therefore suppresses the glue. In \punct, \rlap can be used to "hide" the width of the mark:

%!TeX program = XeLaTeX
\documentclass{article}
\usepackage{xeCJK}
\setCJKmainfont{Noto Sans CJK TC}
\usepackage[overlap,CJK]{ruby}
\usepackage{setspace}
\usepackage{geometry}
\usepackage{parskip}

% Margin Settings
\geometry{
a4paper,
% total={170mm,257mm}, % If you provide the paper size and margins, additionally specifying the text area size doesn't make sense: It will be calculated automatically. 
left=25mm,
right=25mm,
top=30mm,
bottom=20mm
}

% Chinese Pinyin Setttings
\renewcommand\rubysep{-3em}
\renewcommand{\CJKglue}{\hskip 14pt} % \hskip doesn't work without a unit
\renewcommand\rubysize{0.6}
\let\oldruby\ruby
\let\justifying\relax% You used \justifying but that command isn't defined, so I added this to avoid errors. You probably want to delete this line.
\newcommand\punct[1]{% This is the important part: \rlap hides the width, \futurelet... like in \ruby ensures that after the mark glue is inserted as if the mark wasn't there
  \rlap{#1}%
  \futurelet\next\addCJKglue
}
\def\ruby#1#2{\oldruby{#1}{#2}\futurelet\next\addCJKglue}
\def\addCJKglue{\ifx\next\ruby \CJKglue \fi}
\newcommand{\myruby}[2]{\renewcommand\rubysep{-3em}{\chn\ruby{#1}{\textsf{#2}}}}

\newenvironment{chineseenvcustom}[2][2]
  {%
   \rightskip=0pt plus 1em\relax% This avoids overfull boxes by allowing some flexibility at the right border
   \begin{spacing}{#1}%
     \huge \justifying\renewcommand{\CJKglue}{\hskip #2pt\relax}}
  {\end{spacing}}


\begin{document}
\begin{chineseenvcustom}{12}
  \ruby{彌}{Mí}\ruby{勒}{Lè}\ruby{世}{Shì}\ruby{尊}{Zūn}{}\punct{,}\ruby{既}{Jì}\ruby{慈}{Cí}\ruby{隆}{Lóng}\ruby{即}{Jí}\ruby{世}{Shì}\punct{,}\ruby{悲}{Bēi}\ruby{臻}{Zhēn}\ruby{後}{Hòu}\ruby{劫}{Jié}\punct{,}\ruby{依}{Yī}\ruby{事}{Shì}\ruby{題}{Tí}\ruby{名}{Míng}\ruby{弗}{Fú}\ruby{敢}{Gǎn}\ruby{移}{Yí}\ruby{易}{Yì}\punct{.}\ruby{承}{Chéng}\ruby{此}{Cǐ}\ruby{念}{Niàn}\ruby{力}{Lì}\punct{,}\ruby{欲}{Yù}\ruby{守}{Shǒu}\ruby{護}{Hù}\ruby{三}{Sān}\ruby{寶}{Bǎo}\punct{,}\ruby{令}{Lìng}\ruby{魔}{Mó}\ruby{隱}{Yǐn}\ruby{蔽}{Bì}\punct{.}\ruby{摧}{Cūi}\ruby{伏}{Fú}\ruby{自}{Zì}\ruby{大}{Dà}\ruby{增}{Zēng}\ruby{上}{Shàng}\ruby{慢}{Màn}\ruby{者}{Zhě}\punct{,}\ruby{未}{Wèi}\ruby{種}{Zhòng}\ruby{善}{Shàn}\ruby{根}{Gēn}\ruby{者}{Zhě}\punct{,}\ruby{今}{Jīn}\ruby{當}{Dāng}\ruby{令}{Lìng}\ruby{種}{Zhòng}\punct{.}\ruby{已}{Yǐ}\ruby{種}{Zhòng}\ruby{善}{Shàn}\ruby{根}{Gēn}\ruby{者}{Zhě}\punct{,}\ruby{今}{Jīn}\ruby{令}{Lìng}\ruby{增}{Zēng}\ruby{長}{Zhǎng}\punct{.}\ruby{若}{Ruò}\ruby{計}{Jì}\ruby{有}{Yǒu}\ruby{所}{Suǒ}\ruby{得}{Dé}\punct{,}\ruby{住}{Zhù}\ruby{諸}{Zhū}\ruby{見}{Jiàn}\ruby{者}{Zhě}\punct{,}\ruby{皆}{Jiē}\ruby{悉}{Xī}\ruby{令}{Lìng}\ruby{發}{Fā}\ruby{捨}{Shě}\ruby{離}{Lí}\ruby{之}{Zhī}\ruby{心}{Xīn}\punct{.}\ruby{樂}{Lè}\ruby{小}{Xiǎo}\ruby{法}{Fǎ}\ruby{者}{Zhě}\punct{,}\ruby{令}{Lìng}\ruby{不}{Bù}\ruby{疑}{Yí}\ruby{大}{Dà}\ruby{法}{Fǎ}\punct{.}\ruby{樂}{Lè}\ruby{大}{Dà}\ruby{法}{Fǎ}\ruby{者}{Zhě}\punct{,}\ruby{令}{Lìng}\ruby{生}{Shēng}\ruby{歡}{Huān}\ruby{喜}{Xǐ}\punct{.}
\end{chineseenvcustom}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.