3

In Chinese typesetting conventions, book titles are typically enclosed within book title marks "《" and "》," which are UTF-8 Unicode symbols. These symbols can be supported using the xeCJK package (which sets the \catcode of all characters and symbols for Chinese, Japanese, and Korean to 11). I'd like to inquire if there's a method (similar to how shortvrb handles the `|' symbol) to set up a control sequence for "《" and "》," allowing the typesetting of book titles enclosed within these marks to have specific formatting, such as italics or being displayed in blue color, and so on.

chinese character typesetting tex file is usually as the following:

% !TEX program = xelatex
\documentclass{article}
\usepackage{xeCJK}
\begin{document}
Here is a book title in chinese book title marks
《A Chinese Book》
\end{document}

saved as UTF-8 encoding .tex file.

2 Answers 2

3

You can use the active category code to make a command. However, the downside of doing this is that unpaired will result in error.

\documentclass{ctexart}

\begin{document}

\catcode`《 = \active 
\def《#1》{\emph{#1}}

中文

《中文》

《Chinese》

\end{document}
1
  • Great approach! All I need to do is create a control sequence that includes the book title marks '《' before it becomes \active. This way, I can obtain the book title marks in the output and format the book title simultaneously in subsequent typesetting. According to your original definition, the output doesn't include the book title marks.
    – HZ.Zhang
    Dec 16, 2023 at 6:24
4

You can use \newunicodechar:

\documentclass{article}
\usepackage{xeCJK}
\usepackage{newunicodechar}

\newunicodechar{《}{\begingroup《\em\ignorespaces}
\newunicodechar{》}{\/\endgroup》}

\begin{document}

Here is a book title in chinese book title marks
《A Chinese Book》

\end{document}

enter image description here

Alternative approach:

\documentclass{article}
\usepackage{xeCJK}
\usepackage{newunicodechar}

\newunicodechar{《}{《\hzzhangbook|}
\NewDocumentCommand{\hzzhangbook}{r|》}{\emph{#1}》}

\begin{document}

Here is a book title in chinese book title marks
《A Chinese Book》

\end{document}

The difference is that with the latter code, a missing would raise an error; with the former code, the formatting would continue. Take your pick.

1
  • "newunicodechar" is indeed an incredibly useful package! Thank you so much!
    – HZ.Zhang
    Dec 16, 2023 at 6:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .