6

I am making a set of flashcards to help me practice my kanji, and the format I want is quite simple: On the front, I'll have the character, and on the back I will have its meanings and readings (with on-readings and kun-readings on separate lines). I'm using a very nice document class flacards for that, and that works well.

The problem is that some cards are going to have a lot of readings; so many that the list has to wrap. Right now, it's just breaking when the next character doesn't fit (four last lines in image):

undesirable word wrapping

The spaces between each reading is U+3000 IDEOGRAPHIC SPACE ( ), and I would like XeLaTeX to treat that character as a space for word wrapping, so it doesn't break the line in the middle of a reading. In other words, the result should look closer to this (manually constructed example):

desirable word wrapping

...but it must satisfy these criteria:

  • No manual wrapping (if the card gets wider, the line must reflow automatically)
  • Spaces that get removed for wrapping must not be rendered (in the image above, they are)
  • Spaces rendered between individual entries must have exactly the same width as the ideographic space would (even if the font is changed), but it does not have to be an actual ideographic space character in the resulting PDF (however, it would be preferable to have the correct character in there)

The exact entry format is not fixed and may be changed if desirable, as long as the desired spacing is achieved.

MWE:

\PassOptionsToPackage{a4paper}{geometry}
\documentclass[frontgrid,backgrid]{flacards}
\usepackage{xeCJK}
\setCJKmainfont{MS Gothic}
\renewcommand{\cardtextstylef}{\Huge}
\renewcommand{\cardtextstyleb}{}
\begin{document}
\card{明}{bright, clear\\ メイ ミョウ\\ あ(かり) あか(るい) あか(るむ) あか(らむ) あき(らか) あ(ける) -あ(け) あ(く) あ(くる) あ(かす)}
\end{document}
3

You have several questions:

  1. Prevent line breaking between CJK characters. There is a \CJKglue between any two CJK characters, which is initially defined to be \hskip 0pt plus 0.08\baselineskip\relax to enable wrapping. You can redefine \CJKglue to be a empty macro to prevent wrapping.

    (Sorry again for Chinese document of xeCJK only.)

  2. Prevent line breaking before and after . We should treat them to be a CJK ideograph character, rather than fullwidth left or right punctuations. The advanced macro \xeCJKDeclareCharClass in xeCJK does the trick.

  3. Make a full-width space (U+3000) to be a TeX glue, which enables wrapping but is discardable (see TeXbook Chap. 14). This is not difficult for a TeXnician.

Here is the full working example:

enter image description here

\documentclass[frontgrid,backgrid]{flacards}
\renewcommand{\cardtextstylef}{\Huge}
\renewcommand{\cardtextstyleb}{}

\usepackage{xeCJK}
\setCJKmainfont{MS Gothic}

% Prevent line breaking between CJK characters
\xeCJKsetup{CJKglue=}  % or \def\CJKglue{} for old version of xeCJK

% Prevent line breaking before ( and after )
\xeCJKDeclareCharClass{CJK}{`(, `)}

% Define a full-width space to be a \quad, which is a TeX glue
\catcode"3000=\active
\def^^^^3000{\quad}

\begin{document}
\card{明}{bright, clear\\
  メイ ミョウ\\
  あ(かり) あか(るい) あか(るむ) あか(らむ) あき(らか) あ(ける) -あ(け) あ(く) あ(くる) あ(かす)}
\end{document}

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.