# How to set up a Japanese-to-English glossary?

I'm writing my masters thesis in Japanese studies with XeLaTex, and I'd like to insert a glossary that would display 3 elements for each item :

• The original word in Japanese (in kanjis/kanas)
• Its romanized version (romaji)
• Its translation

It doesn't even need to show the pages where each term appears.

Until now, I didn't use such a glossary, I only wanted a function I could use to define how Japanese terms and their translation appeared in the body of the text, so I had simply created a \nihongo function like this :

\documentclass[a4paper, 12pt]{article}

\usepackage{xunicode}
\usepackage{polyglossia}
\usepackage{xeCJK}

\setmainlanguage{french}
\setCJKmainfont{AozoraMinchoRegular.ttf}

\newcommand{\nihongo}[3]{\emph{#1} (#2, «~#3~»)}

\begin{document}
The \nihongo{bakumatsu}{幕末}{end of the shogunate} era
\end{document}


However, I doubt I can use it to build a glossary like the one I need. Is it still possible if I redefine my \nihongo function ? Should I use the glossaries package instead ? If so, how should I customize it so that all 3 elements appear in the glossary ?

• If you use "bakumatsu" again in the document, do you want the parenthetical material repeated? How do you want the glossary ordered? (Sorted according to the romanized version or the original Japanese or have two lists with the romanized and Japanese switched around in the second list?) Should the lists appear at the start of the document (front matter) or end of the document (back matter)? – Nicola Talbot Sep 24 '17 at 10:43
• I only need the parenthetical material the first time, not when the word is repeated. I'd rather have the glossary sorted according to the romanized version, as some of the jury members might not know Japanese and the syllabic order of it. And let's say we put it in the backmatter (can it appear before the bibliography, though ?). – Vic L. Sep 24 '17 at 12:24

Since you're sorting according to the romanized version, that makes it easier. (Neither makeindex nor xindy support Japanese, so you'd be limited to bib2gls to sort according to the kanjis/kanas.)

I don't have your font, so I've had to substitute it to make the example compile so just change it back again.

\documentclass[a4paper, 12pt]{article}

\usepackage{xunicode}
\usepackage{polyglossia}
\usepackage{xeCJK}
\usepackage[style=index]{glossaries}

\setmainlanguage{english}
\setCJKmainfont{Source Han Sans CN}

\newcommand{\nihongo}[3]{\emph{#1} (#2, «~#3~»)}

\makeglossaries

%syntax: \newterm[options]{romaji}{original}{translation}
\newcommand{\newterm}[4][]{%
\newglossaryentry{#2}{%
name={#2},% romanized version
symbol={#3},% original
first={\protect\nihongo{#2}{#3}{#4}},% first use
description={#4},% translation
#1% extra options
}%
}

\newterm{bakumatsu}{幕末}{end of the shogunate}

\begin{document}
The \gls{bakumatsu} era.

Next use: \gls{bakumatsu}.

\printglossaries
\end{document}


If the document is called myDoc.tex then the build process is:

xelatex myDoc
makeglossaries myDoc
xelatex myDoc


This defines a command called \newterm that defines a glossary entry with the name field set to the romanized version, the symbol field set to the original and the description field set to the translation. Each entry has a unique identifying label that can't contain any special characters. Since you're using XeLaTeX there shouldn't be a problem with any extended characters in the label, so in this case the label can be the same as the name field.

The dot after the translation can be suppressed with the package option nopostdot and the page numbering can be hidden using the nonumberlist package option:

\usepackage[style=index,nopostdot,nonumberlist]{glossaries}


The index style inserts the symbol field in parentheses. Not all styles check this field. (See All Styles Provided by glossaries for an overview of all the predefined styles.)

If you can't work out how to run makeglossaries try adding automake:

\usepackage[style=index,nopostdot,nonumberlist,automake]{glossaries}


If you need the next use of \gls{bakumatsu} to also use \emph then just add the text field:

\newcommand{\newterm}[4][]{%
\newglossaryentry{#2}{%
name={#2},% romanized version
symbol={#3},% original
first={\protect\nihongo{#2}{#3}{#4}},% first use
text={\emph{#2}},% next use
description={#4},% translation
#1% extra options
}%
}


It's best to only define terms in the preamble, but if you really need to define terms in the document environment use the extension package glossaries-extra with docdef=restricted. This requires the glossaries to be at the end of the document. (It doesn't matter if the bibliography occurs afterwards, as long as there are no \gls references after \printglossaries.)

\documentclass[a4paper, 12pt]{article}

\usepackage{xunicode}
\usepackage{polyglossia}
\usepackage{xeCJK}
\usepackage[style=index,nonumberlist,docdef=restricted]{glossaries-extra}

\setmainlanguage{english}
\setCJKmainfont{Source Han Sans CN}

\newcommand{\nihongo}[3]{\emph{#1} (#2, «~#3~»)}

\makeglossaries

%syntax: \newterm[options]{romaji}{original}{translation}
\newcommand{\newterm}[4][]{%
\newglossaryentry{#2}{%
name={#2},% romanized version
symbol={#3},% original
first={\protect\nihongo{#2}{#3}{#4}},% first use
text={\emph{#2}},% next use
description={#4},% translation
#1% extra options
}%
}

\newcommand{\provideanduseterm}[4][]{%
\ifglsentryexists{#2}{}{\newterm[#1]{#2}{#3}{#4}}%
\gls{#2}%
}

\begin{document}
The \provideanduseterm{bakumatsu}{幕末}{end of the shogunate} era.

Next use: \gls{bakumatsu}.

\printglossaries
\end{document}


In general it's simplest just to define the terms in the preamble.

Here's another method that assumes the romanized version always needs to be formatted with \emph in the document (but not in the glossary):

\documentclass[a4paper, 12pt]{article}

\usepackage{xunicode}
\usepackage{polyglossia}
\usepackage{xeCJK}
\usepackage[style=index,nonumberlist]{glossaries-extra}

\setmainlanguage{english}
\setCJKmainfont{Source Han Sans CN}

\makeglossaries

%syntax: \newterm[options]{romaji}{original}{translation}
\newcommand{\newterm}[4][]{%
\newglossaryentry{#2}{%
name={#2},% romanized version
symbol={#3},% original
description={#4},% translation
#1% extra options
}%
}

\ifdefempty\glscustomtext
{%
\glsxtrifwasfirstuse
{%
\ifglshassymbol{\glslabel}{\space(\glsaccesssymbol{\glslabel},
«~\glsaccessdesc{\glslabel}~»)}{}%
}%
{}%
}%
{}%
}

% use \emph in the document (but not in the glossary)
\renewcommand*{\glsxtrregularfont}[1]{\emph{#1}}

\newterm{bakumatsu}{幕末}{end of the shogunate}

\begin{document}
The \gls{bakumatsu} era.

Next use: \gls{bakumatsu}.

\printglossaries
\end{document}


This makes it easier to work with commands like \glspl (which uses the plural form).

If you need to use the term in a section heading or caption, use \glsfmttext with glossaries-extra:

\section{The \glsfmttext{bakumatsu} era.}


or \glsentrytext with just the base glossaries package:

\section{The \glsentrytext{bakumatsu} era.}

• Thanks a lot ! I used the last method you presented there. Now the glossary works, and even writing the main text will be much easier. Also, I'd like to use a style with columns and headers, so I checked altlong4col-booktabs, which is nice, but I'd like to make some changes : (1) remove the Page List column, (2) rename the headers, (3) make the first column ("Notation") bold, (4) and invert the positions of the "Description" and "Symbol" columns. Is it possible ? I tried to find a solution by myself, but I'm quite new to TeX and I'd rather not get into huge errors I can't fix. – Vic L. Sep 24 '17 at 21:05
• @VicL. It should be possible to define a style like that. I think it would be best to ask as a separate question. – Nicola Talbot Sep 25 '17 at 10:47
• I asked as a new question here ! Thanks for your help ! – Vic L. Sep 25 '17 at 12:18