1

I am currently struggling with creating a Japanese glossary in Japanese alphabetical order. I've checked and tried this: glossarieswithcjkcharacters however it seems not to work with Lualatex (which I was using for my entire paper), and -- on a sidenote -- when I tried to test, it gave me an error

(! Package inputenc Error: Unicode character 繝 (U+7E5D)
(inputenc)                not set up for use with LaTeX.)

So I tried to work with Lualatex and created a rather simple glossary. However the sorting neither follows the alphabetic order in english or japanese, nor the order of "first appearance" or the order of the list where they were created. Therefore I do not know how to bring them in an order. Most preferably would be the japanese alphabet, which is different from the english one - just a quick example for the first ones: (a, i, u, e, o, ka, ki, ku, ke, ko, sa, shi, su, se, so...)

so this is my code example:

    \documentclass[12pt,a4paper,headings=standardclasses,numbers=noenddot]{scrreprt}
\usepackage[left=2.50cm, right=2.50cm, top=2.50cm, bottom=2.00cm]{geometry}

\usepackage[main=ngerman, english]{babel}
\usepackage[babel, german=quotes]{csquotes}

\usepackage[no-math]{fontspec}
\newfontface\cjkfont{MogaHMinEx90}
\usepackage[no-math,match]{luatexja-preset}
\setmainjfont{MogaHMinEx90}

\usepackage{luatexja-ruby}
\ltjsetparameter{jacharrange={-3}}

\usepackage[record]{glossaries-extra}

\newrobustcmd{\cjkname}[1]{\begin{CJK}{UTF8}{min}#1\end{CJK}}
\glsnoexpandfields
\GlsXtrLoadResources[
  src={entries},% data in entries.bib
  sort=ja,% sort according to Japanese alphabet
  category=japanese
]

\glssetcategoryattribute{japanese}{glossnamefont}{textcjk}
\glssetcategoryattribute{japanese}{glossdescfont}{textcjk}
\glssetcategoryattribute{japanese}{textformat}{textcjk}

\begin{document}
オイルショック
\gls{oilshock} abc 
\printunsrtglossary
\end{document}

This is my glossary entry

    \newglossaryentry{oilshock}{name={\cjkname{オイルショック}},
  description={\cjkname{《和 oil+shock》アラブ産油国の原油生産削減と価格の大幅引き上げが、石油を主なエネルギー資源とする先進工業諸国に与えた深刻な経済的混乱のこと。第一次は昭和48年(1973)、第二次は昭和54年(1979)。石油危機。}}}

\newglossaryentry{fms}{name={cjkname{\ltjruby[]{多|品|種少|生産}{た|ひんしゅ|しょう|せいさん}}},
  description={\cjkname{工場における生産様式の一つで,同一の工場において類似性の低い製品を多品種にしかも1品目あたりは少量生産するもの。}}}  

Is there a neat solution for this or is this completely over-engineering an only 15 page long paper? (I actually really liked the example I linked above, where you could also add dual languages with different ordering)

Sorry, if there are any open questions, as I am still pretty new to LaTeX. Please feel free to ask :) And thank you in advance!

3
  • Your MWE is using the very obsolete glossary package. I'm guessing you meant glossaries, but it's a good idea to compile your MWE before posting. The default setting for the glossaries package is to use makeindex which isn't designed for UTF-8. As I mentioned in my answer to the linked question, xindy doesn't provide support for Japanese, so the best solution is to use bib2gls with glossaries-extra. Feb 11, 2019 at 17:27
  • Thank you very much for your reply! I've added it to the initial question :) would you basically recommend using the linked question's approach (where I got an error (! Package inputenc Error: Unicode character 繝 (U+7E5D) (inputenc) not set up for use with LaTeX.)) or rather use bib2gls in combination with the example above? :)
    – user168390
    Feb 11, 2019 at 17:31
  • It should work with LuaLaTeX. I don't have luatexja-ruby installed, so I can't test it with that. I'll see if I can produce an answer with a trimmed down version of your MWE. Feb 11, 2019 at 17:35

1 Answer 1

1

Since you're using LuaLaTeX rather than PDFLaTeX (which I think the linked question is using), I don't think you need CJKutf8 (which loads inputenc). As I mentioned in the comments, makeindex isn't suitable for UTF-8 and xindy doesn't provide Japanese support, but bib2gls does.

Instead of your glossaries.tex file containing \newglossaryentry, you now need a .bib file containing the glossary data. For example, the file entries.bib contains:

% Encoding: UTF-8

@preamble{"\providecommand{\ltjruby}[3][]{#2#3}"}

@entry{oilshock,
 name={オイルショック},
 description={《和 oil+shock》アラブ産油国の原油生産削減と価格の大幅引き上げが、石油を主なエネルギー資源とする先進工業諸国に与えた深刻な経済的混乱のこと。第一次は昭和48年(1973)、第二次は昭和54年(1979)。石油危機。}
}

@entry{fms,
 name={\ltjruby[]{多|品|種少|生産}{た|ひんしゅ|しょう|せいさん}},
 description={工場における生産様式の一つで,同一の工場において類似性の低い製品を多品種にしかも1品目あたりは少量生産するもの。}
}  

@entry{afghanistanintervention,
 name={アフガン\ltjruby{侵|攻}{しん|こう}},
 description={1979年12月の、ソ連軍によるアフガニスタンへの侵攻。ソ連は1978年調印の友好協力善隣条約に基づく、アフガニスタン政府の要請によるとしたが、反政府派の激しい抵抗と、強い国際的非難にあい、1988年に全面撤退した。}
}  

@entry{communism,
 name={ソ\ltjruby{連|共産|党}{れん| きょうさん|とう}},
 description={1991年8月24日、ゴルバチョフ・ソ連大統領は、ソ連共産党の解散を勧告する声明を出し、自らも共産党書記長の辞任を表明した。事実上の共産党解体宣言であった。}
}

@entry{keizai,
 name={\ltjruby{社会|主義|経済}{しゃかい|しゅぎ|けいざい}},
 description={マルクス主義の未来社会観(共産主義思想)に導かれて樹立されたもので、生産手段の社会的所有に基づいて、社会全体の生産と消費が計画によって調整され、各人の労働に応じて所得分配が行われる経済をいう。}
}

I've trimmed your MWE and used fontspec to set up the fonts (instead of using CJKutf8). I don't have luatexja-ruby installed, and don't know the correct syntax for \ltjruby. I've provided a definition of \ltjruby in the .bib file using \providecommand. This will be ignored if it's already defined earlier in the document (when you uncomment the luatexja-ruby related lines), but the provided definition in @preamble gives bib2gls a guide to sorting. You can modify this definition according to how you want bib2gls to sort that command. For example:

@preamble{"\providecommand{\ltjruby}[3][]{#2}"}

will instruct bib2gls to ignore the first (optional) and third argument, whereas:

@preamble{"\providecommand{\ltjruby}[3][]{#3}"}

will instruct bib2gls to ignore the first and second arguments.

Here's the modified MWE (you may need to change the font names, as appropriate):

\documentclass[12pt,a4paper,headings=standardclasses,numbers=noenddot]{scrreprt}
\usepackage[left=2.50cm, right=2.50cm, top=2.50cm, bottom=2.00cm]{geometry}

\usepackage[main=ngerman, english]{babel}
\usepackage[babel, german=quotes]{csquotes}

%\usepackage{luatexja-ruby}
%\ltjsetparameter{jacharrange={-3}} 

\usepackage{fontspec}
\setmainfont{FreeSerif}
\newfontface\cjkfont{Source Han Sans CN}

\usepackage[record]{glossaries-extra}

\newrobustcmd{\textcjk}[1]{{\cjkfont #1}}

\GlsXtrLoadResources[
  src={entries},% data in entries.bib
  sort=ja,% sort according to Japanese alphabet
  category=japanese
]

\glssetcategoryattribute{japanese}{glossnamefont}{textcjk}
\glssetcategoryattribute{japanese}{glossdescfont}{textcjk}
\glssetcategoryattribute{japanese}{textformat}{textcjk}

\begin{document}
\gls{oilshock} abc \gls{fms} def \gls{afghanistanintervention} ghi \gls{communism} jkl \gls{keizai}
\printunsrtglossary
\end{document}

I don't know any Japanese, but this should order the entries according to the locale provider's collation rules for Japanese. (See the bib2gls manual for more details about the locale provider.) You may get a different glossary list when you uncomment the luatexja-ruby lines.

3
  • Thank you very much for taking the time to walk me through everything! unfortunately, I am facing the same error as when I tried using your initial approach. Using just a different font, since I didn't have Source Han, but I pretty much copypasted your MWE and added japanese characters just to test. \begin{document} \cjkfont{オイルショック} \gls{oilshock} abc \gls{fms} def \gls{afghanistanintervention} ghi \end{document} When I directly write japanese in the document, it shows just fine - however, when I try using the glossary it first gives me [??] (i.imgur.com/QSNOMgA.png)
    – user168390
    Feb 12, 2019 at 12:29
  • Running Bib2Gls then ends in: ! String contains an invalid utf-8 sequence. l.97 {1979蟷エ12譛医 �ョ縲√た騾」霆阪↓繧医k繧「繝輔ぎ... ? (these are not the japanese characters we entered in the bib file)
    – user168390
    Feb 12, 2019 at 12:29
  • I've tried and tested a bit - there seem to be 2 issues. 1st: first compiling (LuaLatex) creates question marks 2nd: the glstex file doesn't compile correctly with Bib2Gls. When I manually changed the entries in glstex.file and compiled LuaLatex, everything looked fine. when i recompiled Bib2Gls, I got the error message with invalid utf-8 sequences again. I am really at a loss, how to fix that. Sorry for all the comments! Thank you!
    – user168390
    Feb 12, 2019 at 14:34

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.