%!TEX TS-program = SpiX
%$ cluttex -e xelatex --synctex=1 --shell-escape --package-support=minted --tex-option=--8bit $texname
% arara: xelatex: { shell: yes, synctex: yes }
\documentclass[a4paper]{article}
\usepackage{kotex}
%\usepackage{fontspec}
%\setmainfont{Noto Serif}
%\setsansfont{Noto Sans}
%\setmonofont{Noto Sans Mono}
\setmainfont{STIX Two Text}

\usepackage{hologo}
\newcommand*\XeTeX{\hologo{XeTeX}}
\newcommand*\XeLaTeX{\hologo{XeLaTeX}}
\newcommand*\LuaTeX{\hologo{LuaTeX}}
\newcommand*\LuaLaTeX{\hologo{LuaLaTeX}}

\usepackage[pmfont={Noto Serif KR}]{pmhanguljamo}
\usepackage[colorlinks]{hyperref}

%\usepackage{polyglossia}
%\setotherlanguage{korean}
%\newfontfamily\hangulfont{UnBatang.ttf}[Script=Hangul,Renderer=OpenType]
%%\newcommand*\jamo[1]{\begingroup\hangulfont\jamoword{#1}}

\setmainhangulfont{Noto Serif CJK KR}

\providecommand*\textkorean[1]{#1}
\newenvironment{korean}{}{}
\newcommand*\jamo[1]{\jamoword{#1}}

\newcommand*\pkg[1]{\textsf{#1}\index{#1}\index{Package!#1}}
\newcommand*\thispkg{\pkg{pmhanguljamo}}
%\maxsecnumdepth{section}

\usepackage{hvextern}
\usepackage{tabularray}

\begin{document}

\title{Poorman's Hangul Jamo Input Method \\ \Large \texttt{pmhanguljamo.sty} }
\author{Kangsoo Kim}
%\date{10 Mar 2021\quad version 0.3.5}
%\date{20 Sep 2021\quad version 0.3.6}
%\date{6 Sep 2022\quad version 0.5.1}
%\date{7 Sep 2022\quad version 0.5.2}
%\date{22 Feb 2023\quad version 1.0.1}
%\date{3 Mar 2023\quad version 1.0.2}
\date{10 Jun 2024\quad version 1.1}

\maketitle

\tableofcontents

\section{Introduction}
This \LaTeX\ package provides Hangul\footnote{%
    \emph{Hangul} is the Korean alphabet 
    to write the Korean language. In both South and North Korea,
    the standard writing system uses Hangul.}
\emph{transliteration} input method, which 
allows to typeset Korean Letters (Hangul) with the help of proper fonts.
The name comes from ``Poorman's Hangul Jamo Input Method.'' It is mainly for
the people who have a system without Korean keyboard IM, but want to typeset
Hangul in their document.
Not only modern Hangul, but so-colled ``Old Hangul'' characters
that uses the lost letters such as `Arae-A'(\textkorean{\jmcc{@}}), `Yes-Ieung'(\textkorean{\jmcc{F}}) or `Pan-Sios'(\textkorean{\jmcc{Z}}) etc.\ can also be typeset.

\XeLaTeX\ or \LuaLaTeX\ is required. The legacy pdf\TeX\ is not supported.
The Korean Language supporting packages such as \pkg{xetexko} and \pkg{luatexko} (in the ko.\TeX\ bundle)
or \pkg{polyglossia} package with Korean support %under \XeLaTeX\  
are recommended, but without them typesetting Hangul is of no problem
with this package \thispkg.

\section{Usage}

\subsection{Loading the package}

Put the following line in your preamble:
\begin{verbatim}
\usepackage[<options>]{pmhanguljamo}
\end{verbatim}

\subsection{Package options}

The package provides three kinds of Hangul input methods. 
You should select one of them with the package option.
And you have to specify just one of them. Mixing ways of transliteration is not
allowed.

\begin{enumerate}
\item \texttt{[method=pm]}. It is an original method of this package. In section~\ref{sec:pmmethod} we will explain about it. If \texttt{method=} option is missing, this one will be activated.
\item \texttt{[method=rrk]} or \texttt{[rrk]}, \texttt{[RRK]}. The \emph{Standard Korean Romanization Transliteration} input method.
In section~\ref{sec:rrk},
we will explain about it. 
\item \texttt{[method=frkim]} or \texttt{[frkim]}. A newly introduced rule. See section~\ref{sec:frkim}.
\end{enumerate}

Whatever method you selected, the following basic options are common.

\begin{enumerate}
\item \texttt{pmfont=<fontname>}. The font that is used to typeset Hangul 
characters in the scope of \verb|\jamoword| or \texttt{jamotext}. If this option missing, the Jamo-Hangul font is to be same as the \textit{main font} of 
the document.

\item \texttt{pmfontfeature=<fontfeature>}. It is possible to provide \emph{font features} to
the font selected as \texttt{pmfont}.
\end{enumerate}

\subsection{Commands and Environment Provided}

The main command to typeset Hangul is \verb|\jamoword|.

\begin{quote}
Input:
\verb|\jamoword{han/gvr/vi yeis i/rvm/vn hun/min/jeq/vm/i/da/.}|\\
Result: \textkorean{\jamoword{han/gvr/vi yeis i/rvm/vn hun/min/jeq/vm/i/da/.}}
\end{quote}

The argument of the command consists of roman alphabets 
and a few marks that represent Hangul Jamo.
In the example we showed the \texttt{[method=pm]} way
which is explained in the section~\ref{sec:pmmethod}. 
But with any other rule it will make the same result.

And an environment \emph{jamotext} is provided.
In the environment, multiple paragraphs can be located. So, it is
suitable to typeset longer text stuffs. For example,
\begin{verbatim}
\begin{jamotext}
jug/nvn nar/gga/ji ha/nvr/vr u/re/re \\
han jem bu/ggv/rem ebs/gi/rvr 

ip/sai/ei i/nvn ba/ram/ei/do \\
na/nvn goi/ro/ue/haiss/da/.
\end{jamotext}
\end{verbatim}
Result:
\begin{quote}
\begin{korean}
\begin{jamotext}
jug/nvn nar/gga/ji ha/nvr/vr u/re/re \\
han jem bu/ggv/rem ebs/gi/rvr 

ip/sai/ei i/nvn ba/ram/ei/do \\
na/nvn goi/ro/ue/haiss/da/.
\end{jamotext}
\end{korean}
\end{quote}

\subsection{Setting up in your Preamble}

Without any other packages, you can type Hangul. Be sure that
proper fonts should be declared for Hangul, utilizing \pkg{fontspec}.

\begin{externalDocument}[ 
	compiler=xelatex,
	code,
	lstOptions={basicstyle=\ttfamily},
	cleanup]{testa}
\documentclass{standalone}
%StartVisiblePreamble
\usepackage{fontspec}
\usepackage[pmfont={Noto Serif KR}]{pmhanguljamo}
%StopVisiblePreamble
\begin{document}
\jamoword{an/nyeq/ha/sei/yo}
\end{document}
\end{externalDocument}

If you don't want to specify \texttt{pmfont} option, you should manually
declare the proper font for Jamo Hangul with \texttt{Script=Hangul} option.\footnote{See section \ref{sec:font}.}

\begin{externalDocument}[ 
	compiler=xelatex,
	code,
	lstOptions={basicstyle=\ttfamily},
	cleanup]{testa}
\documentclass{standalone}
%StartVisiblePreamble
\usepackage{fontspec}
\usepackage{pmhanguljamo}
\newfontfamily\mypmfont{Noto Serif KR}[Script=Hangul]
%StopVisiblePreamble
\begin{document}
\mypmfont\jamoword{an/nyeq/ha/sei/yo}
\end{document}
\end{externalDocument}

%\texttt{UnBatang.ttf} is a font shipped in \pkg{unfonts-core} package of \TeX\,Live.
Not all Korean fonts are available to typeset so-called `Old Hangul',
because they happen to lack
the feature of composing Korean syllables from conjoining Jamo codes. Fortunately,
we have a few more fonts besides \texttt{UnBatang} that are \emph{proper}
and freely available, which are listed in the section~\ref{sec:font}.
In \TeX\,Live distribution, \texttt{UnBatang} is the only \emph{proper} one.

The \pkg{polyglossia} package provides Korean language support. \thispkg\
can be used with it. The following is an example.

\begin{externalDocument}[ 
	compiler=xelatex,
	code,
	lstOptions={basicstyle=\ttfamily},
	cleanup]{testa}
\documentclass{standalone}
%StartVisiblePreamble
\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{korean}
\newfontfamily\hangulfont{Noto Serif KR}[Script=Hangul]
\usepackage{pmhanguljamo}
%StopVisiblePreamble
\begin{document}
\begin{korean}
\jamoword{a/rvm/da/un han/gvr/ib/ni/da/.}
\end{korean}
\end{document}
\end{externalDocument}

In this example, the Korean language is set as `other language',
and the default font for Korean is declared as `\verb|\hangulfont|'.
In the \textit{korean} environment, the \verb|\hangulfont| will be
used for Hangul.

Or the ko.\TeX\ package bundle can be used together.

\begin{externalDocument}[ 
	compiler=xelatex,
	code,
	lstOptions={basicstyle=\ttfamily},
	cleanup]{testa}
\documentclass{standalone}
%StartVisiblePreamble
\usepackage{kotex}
\usepackage[pmfont={NotoSerifKR-Regular.otf}]{pmhanguljamo}
%StopVisiblePreamble
\begin{document}
\jamoword{na/ras/mar/ss@/mi}
\end{document}
\end{externalDocument}

When ko.\TeX\ is used, the fontspec command for Hangul is not
\verb|\fontspec| but \verb|\hangulfontspec|. We recommend that
you use \texttt{pmfont=} option to avoid the complicated situation.

%The \verb|[Script=Hangul]| should be given
%to the font settings for Hangul. For more information, see section~\ref{sec:font}.

The Korean writing system does not have hyphenation rules.
The line breaking can occur just after almost every syllable. Therefore,
without Korean language supporting packages the line breaking and
justification of paragraphs will not be satisfactory.
However when just single or a few Hangul characters are needed, for example in the case of typesetting
the author's name in Hangul, this package provides a casual way to print them out.


\section{Proper Fonts}\label{sec:font}

In order to typeset Hangul characters successfully with the input method
of this package, the help of the \emph{proper} font is crucial.
What we call \emph{proper} font is the font that has the Opentype feature of `Script Hangul', that is, the feature of conjoining jamo characters.
A Truetype font may have this Opentype feature.
Otherwise, it is regarded as an \emph{improper} font.

Not so many fonts are \emph{proper}. 
The fonts or font families listed in the following lines are 
what we know \emph{proper}.
They can be downloaded from the url and used freely. And note that
\texttt{UnBatang} is already installed in your \TeX\,Live installation.
But the author recommends the Noto Korean fonts for this purpose.

\begin{description}
\item[Hamchorom or Hamchorom-LVT] Hamchorom fonts by Hancom Inc., 
\url{https://www.hancom.com/cs_center/csDownload.do},
and their variants with GSUB tables by KTS (the Korean \TeX\ Society).  \url{https://github.com/dohyunkim/hcr-lvt}
\item[KoPub World] free fonts by Korea Publisher Society. 
\url{https://www.kopus.org/biz-electronic-font2/}.
\item[Malgun Gothic] One of Windows 10 system fonts. 
\item[Nanum Yet Hangul] Two font families from Naver. Nanum Myeongjo Yet Hangeul and Nanum Barun Gothic Yet Hangeul. \url{https://hangeul.naver.com/2014/archaicword}
\item[Noto Korean or Source Han] Google's Noto Korean fonts --- Noto Serif Korean, Noto Sans Korean. Or Adobe's Source Han fonts. 
\url{https://fonts.google.com}.
\item[Un Batang] \verb|UnBatang.ttf|. on CTAN. \url{https://ctan.org/pkg/unfonts-core}
\end{description}

To conjoining Jamos to build a syllable with one of these fonts, 
it is necessary to provide
the \texttt{[Script=Hangul]} option.\footnote{%
	the option should be \\
	\texttt{[Script=Hangul,Renderer=Harfbuzz]}\\
	or\\
	\texttt{[Script=Hangul,Renderer=OpenType]},\\
	when the document is processed with \LuaLaTeX.}
%	The \LuaLaTeX\ version should be over 1.11, that is,
%	the \LaTeX\ format of LuaHB\TeX\ is needed.}
But when the package option \texttt{[pmfont=]} is given,
that will be done by the package automatically.

For example, you can specify Hamchorom Batang LVT font by yourself as like:
\begin{verbatim}
\newfontfamily\pmjamofont{HCR Batang LVT}[Script=Hangul]
\end{verbatim}
and then issue \verb|\pmjamofont| command in the scope of Hangul to be typeset.\footnote{%
	When \texttt{pmfont=} option is given, the \texttt{Script=Hangul} is
	automatically activated by the package.}
But these processes will be done by the package itself when 
\begin{verbatim}
\usepackage[pmfont={HCR Batang LVT}]{pmhanguljamo}
\end{verbatim}
is declared in the preamble.

It is recommended that the \emph{proper} font should be used consistently.

\medskip

In case the font you take is not \emph{proper}, you are to meet the warning
message at the console and log file,
\begin{verbatim}
 Package fontspec Warning: (fontspec)
 Font "batang" does not contain requested Script "Hangul".
\end{verbatim}
However, when \XeLaTeX\ is concerned, it is known that the \emph{Modern} Korean Characters (\emph{Hangul Precomposed Syllables} in the Unicode block [U+AC00] -- [U+D7A3]) can be rendered with this kind of font, in spite of the warning message. 


\section{Transliteration Rule of This Package: \texttt{[method=pm]}}\label{sec:pmmethod}

\subsection{Tone Marks and Syllable Serapator}

This method assumes that every Hangul syllable has \emph{Tone Mark} which
must be explicitly put at the end of it. Table~\ref{tab:tonemark} 
shows the input scheme of them.

\begin{table}[h]
\centering
\caption{Tone Marks} \label{tab:tonemark}
\begin{tabular}{c|l}
\hline
input & description \\ \hline
\texttt{/} & for \emph{PyeongSeong}, no dot \\ \hline
\texttt{;} & for \emph{GeoSeong}, single dot on the left of a character, [U+302E] \\ \hline
\texttt{:} & for \emph{SangSeong}, double dots on the left of a character, [U+302F] \\ \hline
\end{tabular}
\end{table}

The tone marks were used in the 15th century, but in the modern Korean they are
out of use. Nevertheless the \verb|/| mark in this package is also used in order to depict
the completion of composing a syllable --- i.e., syllable separator. So DO NOT miss it.

However, it is possible to omit `\verb|/|' mark at the end of a word, i.e., just before \texttt{<space>}, or at the end of the argument of \verb|\jamoword|.
Note that before the puctuation mark --- period, comma, etc., omitting \verb|/| is not permitted.

\subsection{Transliteration rules}

\subsubsection{Consonants}

Table~\ref{tab:cons} shows the transliteration rule for the consonants which are
used in the leading and trailing position of a syllable.

\begin{table}[h]
\centering
\caption{Consonants} \label{tab:cons}
\fontspec{UnDotum.ttf}
\begin{tabular}{ll|ll|ll|ll}
\hline
ㄱ & g & ㄴ & n & ㄷ & d & ㄹ & r \\
ㅁ & m & ㅂ & b & ㅅ & s & ㅇ & \textbf{q} \\
ㅈ & j & ㅊ & c & ㅋ & k & ㅌ & t \\
ㅍ & p & ㅎ & h & \char"3181 & \textbf{f} & \char"317F & \textbf{z} \\
\char"3186 & \textbf{x} & & w & & & & \\
\hline 
\end{tabular}
\end{table}

\begin{enumerate}
\item The corresponding letters ``g, n, d, m, b, s, j, k, t, p, h'' are 
the same as Korean Romanization Method (RRK).\footnote{The \emph{Revised Romanization of Korean} 1995:2000 is the official Korean language romanization system in South Korea.}
\item The letter for `\textkorean{\jmcc{R}}' is allocated to \texttt{r} not \texttt{l}. The latter is reserved for another purpose, cf. item \ref{itm:llr}.
\item The letter `c' is for `\textkorean{\jmcc{C}}'. In the RRK, it is `\texttt{ch}' there.
\item The letter for `\textkorean{\jmcc{Q}}' is \texttt{q}, which is a bit strange, but commonly accepted `\texttt{ng}' was not to be chosen. It is reserved for another consonant `\textkorean{\jamoword{@ng/}}'
\item The letters `f, z, x' are more freely selected. These letters are the lost ones in Modern Korean.
\item The `light labial consonants', \textkorean{\jmcc{BQ}, \jmcc{PQ}} in the Old Hangul can be input as `bq, pq, bbq, mq'. 
%\footnote{\emph{Jungseong Filler} is not provided.} 
\item\label{itm:llr} The letters `l' and `lr' are 
prepared for very rare case. In the 15th century Korean, `\textkorean{\jamoword{sla}}' and
`\textkorean{\jamoword{slra}}' were distinguishable. `sl' is chosen for the SIOS with left branch being longer, and `slr' means right branch longer. The same is the case `ssl', `sslr', `jl', `jlr' etc.
\item In the Modern Korean, only `gg, dd, bb, ss, jj' are additionally permitted in the leading consonant position,
But in the Old Hangul this limitation was not applied. So \emph{Choseong} can have multiple consonants, e.g., `bsg', `bsd', `ss', `sd' etc.
\item The leading `zero consonant' can be omitted. So if a syllable begins with vowel, then the leading `\textkorean{\jmcc{Q}}' will appear. You can write the leading `\verb|q|' of a syllable or not.
For example, `\verb|\jamoword{qaq}|' and `\verb|\jamoword{aq}|' will generate the same result `\jamo{qaq}'.
\item The letter `w' is chosen to present \emph{Choseong Filler}. For example, \verb|\jamoword{wan}| renders \jamoword{wan}.
\item [compatibility] The letters that `x', `q', and `f' corresponds to are changed from version 1.0. If the style of former version is needed, put \texttt{[compat=0.5]} option in the \verb|\usepackage| line. Then \texttt{x} will be rendered as `\jmcc{Q}', \texttt{q} as `\jmcc{F}', and \texttt{f} as `\jmcc{X}'.
\end{enumerate}

\subsubsection{Vowels}

Table~\ref{tab:vow} shows the transliteration rule for vowels. 

\begin{table}[h]
\centering
\caption{Vowels}\label{tab:vow}
\ttfamily\fontspec{UnDotum.ttf}
\begin{tabular}{ll|ll|ll|ll|ll}
\hline
ㅏ & a & ㅓ & e & ㅗ & o & ㅜ & u & ㅡ & \textbf{v} \\
ㅣ & i & \jmcc{@} & \textbf{@}  & & & & & & \\ \hline
ㅑ & ya & ㅕ & ye & ㅛ & yo & ㅠ & yu & \kern-.3em\jmcc{@}\kern-.6em\jmcc{@} & @@ \\ \hline
ㅐ & ay, ai & ㅔ & ey, ei & ㅚ & oy, oi & ㅟ & uy, ui & ㅢ & vy, vi \\ 
ㅒ & yay, yai & ㅖ & yey, yei & \jmcc{YOI} & yoi & \jmcc{YUI} & yui & \jmcc{@I} & @i \\ \hline
ㅘ & oa & ㅙ & oay, oai & ㅝ & ue & ㅞ & uey, uei &  & * \\ \hline
\end{tabular}
\end{table}

\begin{enumerate}
\item The rule for vowels may look a bit unfamiliar. But it is simple and easily rememberable.

\item The letter `v' is never considered to be a vowel. But this package 
determined it to stand for the vowel `\textkorean{\jmcc{V}}'. In fact,
the roman alphabets fall short of the vowels. This allocation is arbitrary.

\item The lost `Arae-A' is allocated to `@', and the rare `Double Arae-A' to `@@', which are forgotten vowels in Modern Korean.

\item The \emph{Jungseong Filler} ([U+1160]) can be input with \verb|*|. For example, \verb|\jamoword{h*n}| renders \jamoword{h*n}.
\end{enumerate}

\subsubsection{Compatibility Jamos}

The compatibility Jamo block in Unicode contains several Hangul Jamo characters,
which cannot be used to compose Hangul syllables, and are considered
independent Jamo characters respectively.

To input the compatibility Jamos in the arguments of \verb|\jamoword| or \verb|jamotext|, 
you are to type them in their capital letters (upper cases). And every compatibility Jamo has to be
separated with syllable separator --- \verb|/|. 
Because the \verb|@| character has no upper case, write \verb|W| instead of \verb|@| to display compatibility `Arae-A'.

Here is an example:
\begin{quote}
\begin{verbatim}
\jamoword{W/nvn a/rai/a/ra/go bu/rv/go A/oa 
    bi/svs/ha/gei irg/nvn/da}
\end{verbatim}
\textkorean{\jamoword{W/nvn a/rai/a/ra/go bu/rv/go A/oa bi/svs/ha/gei irg/nvn/da}}
\end{quote}

\subsection{ASCII-Escaping Trick}
Sometimes it is needed to locate a few math materials or ASCII stuffs
in the midst of Jamo Hangul texts. The tricky syntax 
\begin{verbatim}
   !{<ASCII stuffs>}
\end{verbatim}
makes it possible to insert non-Jamo ASCII characters into \texttt{jamotext}
context. Note that it is not allowed in the arguments of \verb|\jamoword|.

\begin{verbatim}
\begin{jamotext}
in/gan/i pog/jeq/goa eg/ab/ei 
!{tyranny and oppression} 
dai/haq/ha/nvn ma/ji/mag su/dan/v/ro/se 
!{as a last resort}
ban/ran/vr ir/v/ki/do/rog gaq/yo/bad/ji 
anh/v/rye/myen

pi/ta/go/ra/sv/vi jeq/ri/ !{\unskip :} 
!{$a^2+b^2=c^2$}.
\end{jamotext}
\end{verbatim}

\noindent Result:\\
\begin{jamotext}
in/gan/i pog/jeq/goa eg/ab/ei 
!{tyranny and oppression} 
dai/haq/ha/nvn ma/ji/mag su/dan/v/ro/se 
!{as a last resort}
ban/ran/vr ir/v/ki/do/rog gaq/yo/bad/ji 
anh/v/rye/myen

pi/ta/go/ra/sv/vi jeq/ri/ !{\unskip :} !{$a^2+b^2=c^2$}.
\end{jamotext}

\bigskip

The \verb|!{| mark must be located in the head of a word.
(To remove the preceding space of a word, \verb|\unskip| is
used in the example.) This trick will be useful when using
math equations, \LaTeX\ macros, or English words along with long Jamo Hangul texts.

By the time this ASCII-escaping trick is available with \texttt{method=pm} and \texttt{method=frkim}.
And do not forget that it can be used only in the \texttt{jamotext}
environment.

\subsection{Examples: \texttt{method=pm}}\label{sec:exam}

Now, we will show a few practical examples, where
the \emph{korean} environment of \pkg{polyglossia} package is used.
The preamble is like this:

\begin{verbatim}
\usepackage{pmhanguljamo}
\usepackage{polyglossia}
\setotherlanguage{korean}
\newfontfamily\hangulfont{Noto Serif KR}[Script=Hangul]
\end{verbatim}

\subsubsection{Modern Hangul}\label{sec:exammodern}

%\begin{verbatim}
%\begin{korean}
%\begin{jamotext}
%e/rin/i/nvn na/ra/oa gye/rey/vi ap/nar/vr i/e/na/gar 
%sai/sa/ram/i/mv/ro gv/dvr/vi mom/goa ma/vm/vr gui/hi 
%ye/gye orh/go a/rvm/dab/go ssig/ssig/ha/gey ja/ra/do/rog 
%him/sse/ya han/da/.
%\end{jamotext}
%\end{korean}
%
%\begin{enumerate}
%\item \textkorean{\jamoword{e/rin/i/nvn in/gan/v/ro/se 
%jon/jux/ha/ye/ya ha/mye sa/hoi/vi han sa/ram/v/ro/se 
%or/ba/rv/gey ki/ue/ya han/da/.}}
%\end{enumerate}
%\end{verbatim}
%
%\begin{quotation}
%\begin{korean}
%\begin{jamotext}
%e/rin/i/nvn na/ra/oa gye/rey/vi ap/nar/vr i/e/na/gar 
%sai/sa/ram/i/mv/ro gv/dvr/vi mom/goa ma/vm/vr gui/hi 
%ye/gye orh/go a/rvm/dab/go ssig/ssig/ha/gey ja/ra/do/rog 
%him/sse/ya han/da/.
%\end{jamotext}
%\end{korean}
%
%\begin{enumerate}
%\item \textkorean{\jamoword{e/rin/i/nvn in/gan/v/ro/se 
%jon/jux/ha/ye/ya ha/mye sa/hoi/vi han sa/ram/v/ro/se 
%or/ba/rv/gey ki/ue/ya han/da/.}}
%\end{enumerate}
%\end{quotation}

\begin{verbatim}
\begin{verse}
\begin{korean}
\begin{jamotext}
na bo/gi/ga yeg/gye/ue \\
ga/sir ddai/ei/nvn \\
mar ebs/i go/i bo/nai dv/ri/u/ri/da/.

yeq/byen/ei yag/san \\
jin/dar/rai ggoc \\
a/rvm dda/da ga/sir gir/ei bbu/ri/u/ri/da/.

ga/si/nvn ger/vm ger/vm \\
noh/in gv ggoc/vr \\
sa/bbun/hi jv/rye/barb/go ga/si/ob/so/se

na bo/gi/ga yeg/gye/ue \\
ga/sir ddai/ei/nvn \\
jug/e/do a/ni nun/mur hvr/ri/u/ri/da/.
\end{jamotext}
\end{korean}
\end{verse}
\end{verbatim}

\begin{verse}
\begin{korean}
\begin{jamotext}
na bo/gi/ga yeg/gye/ue \\
ga/sir ddai/ei/nvn \\
mar ebs/i go/i bo/nai dv/ri/u/ri/da/.

yeq/byen/ei yag/san \\
jin/dar/rai ggoc \\
a/rvm dda/da ga/sir gir/ei bbu/ri/u/ri/da/.

ga/si/nvn ger/vm ger/vm \\
noh/in gv ggoc/vr \\
sa/bbun/hi jv/rye/barb/go ga/si/ob/so/se

na bo/gi/ga yeg/gye/ue \\
ga/sir ddai/ei/nvn \\
jug/e/do a/ni nun/mur hvr/ri/u/ri/da/.
\end{jamotext}
\end{korean}
\end{verse}

\subsubsection{pre-1933 Hangul}

A 15th century text with tone marks (\emph{BangJeom}).

\begin{verbatim}
\begin{korean}
\begin{jamotext}
	na/ras;mar:ss@/mi;
	中dyuf/國guig;ei; dar/a;
	文mun/字jj@q;oa;ro; se/rv/ s@/m@s/di; a/ni;h@r/ss@i;
	i;ren jyen/c@;ro; e/rin; 百b@ig;姓syef;i; 
	ni/rv/go;jye; horx; bai; i/sye;do;
	m@/c@m;nai: jei bdv;dvr; si/re; pye/di; mod:h@rx no;mi; ha/ni;ra
\end{jamotext}
\end{korean}
\end{verbatim}

\begin{quote}
\begin{korean}
\begin{jamotext}
	na/ras;mar:ss@/mi;
	中dyuf/國guig;ei; dar/a;
	文mun/字jj@q;oa;ro; se/rv/ s@/m@s/di; a/ni;h@r/ss@i;
	i;ren jyen/c@;ro; e/rin; 百b@ig;姓syef;i; 
	ni/rv/go;jye; horx; bai; i/sye;do;
	m@/c@m;nai: jei bdv;dvr; si/re; pye/di; mod:h@rx no;mi; ha/ni;ra
\end{jamotext}
\end{korean}
\end{quote}

And another example of 17th century, from \jamo{du/si/en/hai}, \emph{Selected Translations of 
Du Fu's Poems}, without tone marks.

\begin{verbatim}
\begin{verse}
\begin{korean}
\begin{jamotext}
g@/r@/mi p@/r@/ni sai de/ug h@i/o/,\\
moy/hi pe/re/h@/ni gos/ bi/ci bvr bvd/n@n d@s/do/da/.\\
ors bo/mi bon/d@in sdo di/na/ga/n@/ni \\
e/nv na/ri i do/ra/gar h@i/o/.
\end{jamotext}
\end{korean}
\end{verse}
\end{verbatim}

\begin{verse}
\begin{korean}
\begin{jamotext}
g@/r@/mi p@/r@/ni sai de/ug h@i/o/,\\
moy/hi pe/re/h@/ni gos/ bi/ci bvr bvd/n@n d@s/do/da/.\\
ors bo/mi bon/d@in sdo di/na/ga/n@/ni \\
e/nv na/ri i do/ra/gar h@i/o/.
\end{jamotext}
\end{korean}
\end{verse}

\let\jamoword\relax
\let\jamotext\relax
\let\endjamotext\relax
\ExplSyntaxOn
\input pmhanguljamo-rrk.sty
\ExplSyntaxOff


\section{The RRK Input Method: \texttt{[method=rrk]}} \label{sec:rrk}

In chapter 3 section 8 of \emph{Revised Romanization of Korean} (2000),
the `transliteration method' of Hangul romanization is declared. 
It is exceptionally permitted when it is required to restore
the original Hangul writings, while standard is the phonetic transcription one.
So we can make use of the former as an input method.

If the package option \texttt{[method=rrk]} is given, 
the RRK method is activated. With this rule, only `Modern Hangul' can
be typeset. You can give the option by the abbreviation form \texttt{[rrk]} or \texttt{[RRK]}.


\subsection{Transliteration Rule of RRK}

Table~\ref{tab:rrkcons} and \ref{tab:rrkvow} show the
RRK transliteration rule.

\begin{table}[h]
\centering
\caption{RRK Consonants} \label{tab:rrkcons}
\fontspec{UnDotum.ttf}
\begin{tabular}{ll|ll|ll|ll|ll|ll}
\hline
ㄱ & g & ㄲ & kk & ㅋ & k & ㄷ & d & ㄸ & tt & ㅌ & t \\
ㅂ & b & ㅃ & pp & ㅍ & p & ㅈ & j & ㅉ & jj & ㅊ & ch \\
ㅅ & s & ㅆ & ss & ㅎ & h & & & & & & \\ \hline
ㄴ & n & ㅁ & m & ㅇ & ng & ㄹ & l & & & & \\ \hline
\end{tabular}
\end{table}

\begin{table}[h]
\centering
\caption{RRK Vowels} \label{tab:rrkvow}
\fontspec{UnDotum.ttf}
\begin{tabular}{ll|ll|ll|ll|ll|ll}
\hline
ㅏ & a & ㅓ & eo & ㅗ & o &  ㅜ & u & ㅡ & eu & ㅣ & i\\ 
ㅐ & ae & ㅔ & e & ㅚ & oe & ㅟ & wi &  & & & \\ \hline
ㅑ & ya & ㅕ & yeo  & ㅛ & yo & ㅠ & yu & ㅒ & yae & ㅖ & ye \\
ㅘ & wa & ㅙ & wae & ㅝ & wo & ㅞ & we & ㅢ & ui & &  \\ \hline
 \end{tabular}
 \end{table}

\begin{enumerate}
\item When the leading consonant `{\fontspec{UnBatang}\jmcc{Q}}' is placed
at the head of a word, it can be ommitted. Otherwise the hyphen character (\verb|-|) should exist. For example, \\
\verb|\jamoword{annyeonghase-yo}| \textkorean{\jamoword{annyeonghase-yo}} \\
\verb|\jamoword{jung-ang jungang}| \textkorean{\jamoword{jung-ang jungang}} \\
\verb|\jamoword{ha-yeossseubnida}| \textkorean{\jamoword{ha-yeossseubnida}}

\item The hyphen character \verb|-| can also be used to forcibly separate syllables.
And the special character \verb|/| is taken as another syllable separator.
They are exchangeable.\\
\verb|\jamoword{haeb/ssal haeb-ssal}| \textkorean{\jamoword{haeb/ssal haeb-ssal}}

\item The six pucntuation marks, \texttt{.} \texttt{,} \texttt{!} \texttt{?} \texttt{;} \texttt{:} can be located in the Hangul scope.
The others are not allowed.\\
\verb|\jamoword{a! malg-eun haneul, si-wonhan baram.}| \\
\textkorean{\jamoword{a! malg-eun haneul, si-wonhan baram.}}\\
The \LaTeX\ quotes, \verb|``|, \verb|''|, \verb|`| and \verb|'| cannot be used
within Hangul input scope. They should be located outside.
However you can use unicode quotes, \verb|“| and \verb|”|, which can be input
with syllable separator. For example, \\
\verb|\jamoword{“/hangeul/”/ilan hangug-eoleul jeogneun geul-ida.}|\\
\textkorean{\jamoword{“/hangeul/”/ilan hangug-eoleul jeogneun geul-ida.}}\\
In this case, the syllable separator \verb|/| cannot be replaced by hyphen character.

\item The leading consonant `\textkorean{\jmcc{R}}' is written with 
either \texttt{l} or \texttt{r}, while the trailing one should be \texttt{l}.\\
\verb|\jamoword{noraereul nolaeleul}| \textkorean{\jamoword{noraereul nolaeleul}}

\item We made it possible to use `Arae-A' with the RRK method.
Though it is not present in Modern Hangul writing system, typesetting
`Jeju language' or some pre-1933 Korean texts will be made easy with this.
The `Arae-A' is to be input as `\texttt{@}' character, and the `Double Arae-A' `\texttt{@@}'. There is one exception. The one word with one letter that
has only leading `@', i.e., \textkorean{\jamoword{x@}} should be input by `\verb|x@|'. 
If the syllable has trailing consonants or is part of a word, just \verb|@| is
good. \\
\verb|\jamoword{h@ngeul @@nam-eun}| \textkorean{\jamoword{h@ngeul @@nam-eun}}. 
\end{enumerate}

\subsection{Example of RRK method}

The text is one of the most famous poem in Korean, \textkorean{\jamoword{jindallaekkoch}} \emph{Azalea} by Kim So-wol.\footnote{%
	An English translation of this poem can be read in Wikipedia, 
	\url{https://en.wikipedia.org/wiki/Kim_Sowol}.}
In section~\ref{sec:exammodern}, we showed default way of inputting 
the poem. The \textit{korean} environment and font settings are 
the same as in section~\ref{sec:exam}.

\begin{verbatim}
\begin{verse}
\begin{korean}
\begin{jamotext}
na bogiga yeoggyeo-wo \\
gasil ttae-eneun \\
mal eobs-i go-i bonae deuli-ulida.

yeongbyeon-e yagsan \\
jindallae kkoch \\
aleum ttada gasil gil-e ppuli-ulida.

gasineun geol-eum geol-eum \\
noh-in geu kkoch-eul \\
sappunhi jeulyeobalbgo gasi-obsoseo

na bogiga yeoggyeo-wo \\
gasil ttae-eneun \\
jug-eodo ani nunmul heulli-ulida.
\end{jamotext}
\end{korean}
\end{verse}
\end{verbatim}

\begin{verse}
\begin{korean}
\begin{jamotext}
na bogiga yeoggyeo-wo \\
gasil ttae-eneun \\
mal eobs-i go-i bonae deuli-ulida.

yeongbyeon-e yagsan \\
jindallae kkoch \\
aleum ttada gasil gil-e ppuli-ulida.

gasineun geol-eum geol-eum \\
noh-in geu kkoch-eul \\
sappunhi jeulyeobalbgo gasi-obsoseo

na bogiga yeoggyeo-wo \\
gasil ttae-eneun \\
jug-eodo ani nunmul heulli-ulida.
\end{jamotext}
\end{korean}
\end{verse}

\ExplSyntaxOn
\cs_undefine:N \jamoul
\cs_undefine:N \l_inputword_seq
\cs_undefine:N \l_inputpar_seq
\cs_undefine:N \jamotext
\cs_undefine:N \endjamotext
\cs_undefine:N \jamo_word:nn
\cs_set_eq:NN \frkhangulfont \opt_pmfont_tl 
\cs_set_eq:NN \frkhangulfontfeature \opt_pmfontfeature_tl
\input{pmhanguljamo-frkim.code.tex}
\ExplSyntaxOff


\section{Fukui Rei's Transliteration Rule: \texttt{[method=frkim]}}
\label{sec:frkim}

The \texttt{frkim} stands for ``Fukui Rei's k\TeX{}'' and ``input method''.
Prof.~Fukui Rei (Tokyo University) proposed his own transliteration rules of Hangul romanization, and wrote a \TeX{} macro package named \emph{hangulTeX} in 1993, with
which it was possible to typeset Hangul by roman-alphabet inputs.

To select this rule, give \texttt{[method=frkim]} option to the package.

\subsection{The rule}

Table~\ref{tab:ktex} shows the rule of hangulTeX. All the rules
can be used with this package.

\begin{table}[h]
\centering\small
\caption{The transliteration rule of hangul\TeX}\label{tab:ktex}
\ttfamily
\begin{tblr}{
	colspec={llllllllll},
	hline{1,Z}={1pt},
	hline{2-Y}={.4pt},
	vline{3,5,7,9}={.4pt},
}
\SetCell[c=10]{c,bg=azure5,fg=white} Consonants &&&&&&&&&\\
ㄱ & g & ㄴ & n & ㄷ & d & ㄹ & r & ㅁ & m \\
ㅂ & b & ㅅ & s & ㅇ & ' x & ㅇ & q & ㅈ & j \\
ㅊ & c & ㅋ & k & ㅌ & t & ㅍ & p & ㅎ & h  \\
ㄲ & G & ㄸ & D & ㅃ & B & ㅆ & S & ㅉ & J \\
ㅸ & v & ㅿ& z & ㆁ & Q & ㆆ & X & & \\
%\SetCell[c=10]{l} &&&&&&&&& \\
\end{tblr}
\hfil
\begin{tblr}{
	colspec={llllllll},
	hline{1,Z}={1pt},
	hline{2-Y}={.4pt},
	vline{3,5,7,9}={.4pt},
}
\SetCell[c=8]{c,fg=white,bg=azure5} Vowels &&&&&&&\\
ㅏ & a  & ㅓ & e   & ㅗ & o   & ㅜ & u  \\
ㅡ & y  & ㅣ & i   & ㆍ & @   & ㅑ & ia  \\
ㅕ & ie & ㅛ & io  & ㅠ & iu  & ㅐ & ai \\
ㅔ & ei & ㅒ & iai & ㅖ & iei & ㅘ & oa \\
ㅙ & oai & ㅚ & oi & ㅝ & ue  & ㅞ & uei \\
ㅟ & ui  & ㅢ & yi & ㆎ & @i  &    &  \\
\end{tblr}
\end{table}

\activatefrcccmds
\begin{enumerate}
\item The leading zero-consonant (\frccq) can be input with \verb|'| (right quote) or \verb|x|. The default is \verb|'|, and \verb|\zeroisx| macro
switches this action. And the macros \verb|\rq| can be used in the position of \verb|'| (closing quote) when `zero' is \verb|'| (\verb|\zeroisrq|). For example,
\verb|\hg{{``}gug'e\rq\rq}| \hg{{``}gug'e\rq\rq}. \verb|\zeroisx\hg{{``}gugxe{''}}| {\zeroisx\hg{{``}gugxe{''}}}.

\item The trailing I-Eung (\frccq) is made by \verb|q|, and the lost character
Yes-I-Eung (\frccQ) is by \verb|Q|.

\item Apart from \emph{hangulTeX}, with this package it is permitted to omit the leading zero-consonant in the position of the head of a word. That is, \verb|'annieq| and \verb|annieq| are identical. But if the letter is in the midst of a word, it can not be ommited.

\item The \emph{hangulTeX} commands \verb|\hg|, \verb|\hangul|, and \verb|\endhangul| are provided. And \verb|\jamoword| is the same as \verb|\hg|, 
and \texttt{jamotext} environment can be used with.

\item We extended the Old-Hangul feature of this input method. The plural consonants in the leading position were not implemented in the \emph{hangulTeX}, which can be done by dispicting the starting position of the plural leading consonants with \verb|-| (dash). Moreover, in the heading position of a word,
this mark can be left out. For example, \verb|\hg{bsumei}| \hg{bsumei}; \verb|\hg{gy-bsgyi'iei}| \hg{gy-bsgyi'iei}. 

\item The command \verb|\AddRule| overrides the previous key-letter assignments. Therefore, the user can define his own key-def's for the Hangul Jamos. Read the Korean manual (\texttt{kdoc}) carefully.
\end{enumerate}

\subsection{Examples}

\subsubsection{Modern Hangul}

The following example text was taken from \emph{hangulTeX} manual (1994).
(All the heading \verb|'|'s in every word can be left out now.)

\begin{verbatim}
\hangul
nydas'ebs'i hoiram'i morgo'on pamun'yn 'yi'oiro simgaghan 
ges'i'ese goanrigoa samusir'yi 'ohu najer'yr 'oanjenhi 
gierDannai noh'aSda. goanrigoa jig'uendyr'i GiriGiri mo'ie 
juqgunanbaq'yro Sod'a noh'yn mardyr'yn doro ju'uedam'a 
bomien daicuq 'ui'oa gat'yn nai'ioq'i doigeiSnyndei, 
murron gy ga'undeinyn mindosig'i Siburiedain burpieqdo
saqdaq bubun'yr cajihago 'iS'eSda.

mindosig'yn juro 'os'i nargairanyn jenrai'yi sogdam'yr 
dyr'e gyren joqriu'yi nargairyr dargonyn seisaq'yr huerhuer
nar'adanir su 'ebs'ym'yr nunu'i gaqjohanyn pien'i'eSda. 
gy'yi mar'yn sasaiqhoar'i 'ebs'ejinyn seim'iranyn coqgag
sa'uen 'ugihoan'yi jujaqgoa majbaro toqhaiSda.
\endhangul
\end{verbatim}

\begin{quote}
\hangul
nydas'ebs'i hoiram'i morgo'on pamun'yn 'yi'oiro simgaghan 
ges'i'ese goanrigoa samusir'yi 'ohu najer'yr 'oanjenhi 
gierDannai noh'aSda. goanrigoa jig'uendyr'i GiriGiri mo'ie 
juqgunanbaq'yro Sod'a noh'yn mardyr'yn doro ju'uedam'a 
bomien daicuq 'ui'oa gat'yn nai'ioq'i doigeiSnyndei, 
murron gy ga'undeinyn mindosig'i Siburiedain burpieqdo
saqdaq bubun'yr cajihago 'iS'eSda.

mindosig'yn juro 'os'i nargairanyn jenrai'yi sogdam'yr 
dyr'e gyren joqriu'yi nargairyr dargonyn seisaq'yr huerhuer
nar'adanir su 'ebs'ym'yr nunu'i gaqjohanyn pien'i'eSda. 
gy'yi mar'yn sasaiqhoar'i 'ebs'ejinyn seim'iranyn coqgag
sa'uen 'ugihoan'yi jujaqgoa majbaro toqhaiSda.
\endhangul
\end{quote}

And another example:

\begin{verbatim}
\begin{jamotext}
	caig'yr hanguen gajigo iS'eSji'io. Gaman pioji'ei 
	sonbadagmanhan jag'yn caig'iji'io. cesjaq'yr nemgimien
	nun'i nairigon haji'io.

	baramdo jamdyn supsog, jamdyn hiensasinamudyr tumieqhan
	murgoanman Gai'e iS'eSji'io. gajaq kygo uramhan sasinamu 
	mit'ei daqsin'yn memcu'eSji'io. daqsin'i namuduqci'ei 
	dyq'yr gidaija biroso nun'i nairigi sijaghaiSji'io.
	edi'eidyn dahgiman hamien nog'aberinyn nun.
	gyDaiJym haise Gocnun'i Gai'enaSgeiSji'io.
\end{jamotext}
\end{verbatim}

\begin{quote}
\begin{jamotext}
	caig'yr hanguen gajigo iS'eSji'io. Gaman pioji'ei 
	sonbadagmanhan jag'yn caig'iji'io. cesjaq'yr nemgimien
	nun'i nairigon haji'io.

	baramdo jamdyn supsog, jamdyn hiensasinamudyr tumieqhan
	murgoanman Gai'e iS'eSji'io. gajaq kygo uramhan sasinamu 
	mit'ei daqsin'yn memcu'eSji'io. daqsin'i namuduqci'ei 
	dyq'yr gidaija biroso nun'i nairigi sijaghaiSji'io.
	edi'eidyn dahgiman hamien nog'aberinyn nun.
	gyDaiJym haise Gocnun'i Gai'enaSgeiSji'io.
\end{jamotext}
\end{quote}

The following example shows `ASCII-escaping trick' in
\texttt{jamotext} environment.

\begin{verbatim}
\begin{jamotext}
jiggagsamgaghieq !{$\triangle ABC$}'yi sei bien !{$a,b,c$}
sa'i'ei !{$a^2+b^2=c^2$}'in goangieiga seqribhanda.
\end{jamotext}
\end{verbatim}

\begin{quote}
\begin{jamotext}
jiggagsamgaghieq !{$\triangle ABC$}'yi sei bien !{$a,b,c$}
sa'i'ei !{$a^2+b^2=c^2$}'in goangieiga seqribhanda.
\end{jamotext}
\end{quote}

The font can be changed with \verb|\setpmhangulfont| command.

\begin{verbatim}
\hg{iuguhan iegsa'oa jentoq'ei bicnanyn}
\setpmhangulfont{Noto Sans CJK KR}
\hg{uri daihangugmin'yn}
\end{verbatim}

\begin{quote}
\hg{iuguhan iegsa'oa jentoq'ei bicnanyn}
\setpmhangulfont{Noto Sans CJK KR}
\hg{uri daihangugmin'yn}
\end{quote}

\subsubsection{Old Hangul}

\begin{verbatim}
\jamoword{nagpo'yi sdar'irnienni bando jinsaq oggieq gasda 
	goaqhanjien'yisie jiegsoqja masna mijinjieqhoi
	h@'orca'yi simanh@mi joiga doi'ia siaqjiei d@irohasa
	jintoi'yi n@icisim@i gar ba'yr mornadeni du'iusan
	sir'ieqgieisie bu'in-sd@ig'yro jisih@giro oassa'oni
	e'iebbi iegisosie}
\end{verbatim}

\begin{quote}
\jamoword{nagpo'yi sdar'irnienni bando jinsaq oggieq gasda 
	goaqhanjien'yisie jiegsoqja masna mijinjieqhoi
	h@'orca'yi simanh@mi joiga doi'ia siaqjiei d@irohasa
	jintoi'yi n@icisim@i gar ba'yr mornadeni du'iusan
	sir'ieqgieisie bu'in-sd@ig'yro jisih@giro 
	oassa'oni e'iebbi iegisosie}
\end{quote}

The Tone-Marks (\emph{BangJeom}) are not supported in itself.
But it is easy to facilitate them. See the following case.

\begin{verbatim}
\catcode`\:=\active \catcode`\;=\active
\def:{\char"302F}\def;{\char"302E}
\hg{naras;mar:S@mi; 中diuQ國guig;'ei; dar'a;
    文mun字J@q;'oa;ro; sery s@m@sdi; ani;h@rS@i;
    i;ren jienc@;ro; erin; 百b@ig;姓sieQ;'i nirygo;jie;
    horX; bai; isie;do m@c@m;nai: jei bdy;dyr 
    sire; piedi; mod:h@rX no;mi; hani;ra.}
\end{verbatim}

\begin{quote}
\catcode`\:=\active \catcode`\;=\active
\def:{\char"302F}\def;{\char"302E}
\hg{naras;mar:S@mi; 中diuQ國guig;'ei; dar'a;
    文mun字J@q;'oa;ro; sery s@m@sdi; ani;h@rS@i;
    i;ren jienc@;ro; erin; 百b@ig;姓sieQ;'i nirygo;jie;
    horX; bai; isie;do m@c@m;nai: jei bdy;dyr 
    sire; piedi; mod:h@rX no;mi; hani;ra.}
\end{quote}

\section{Further Information}


For more examples and information about this package, 
please read the documentation 
\href{http://mirrors.ctan.org/language/korean/pmhanguljamo/doc/pmhanguljamo-kdoc.pdf}{\texttt{pmhanguljamo-kdoc.pdf}}
(in Korean).


\section{Acknowledgements}

Thanks go to yihoze at the KTUG board, there he commented, 
``The IM apps I've tried such as Korean Windows Old Hangul IM or Saenaru IM 
were all somewhat inconvenient. $\ldots$\ 
In my opinion, for the foreign scholar who
studies Korean language, especially Middle Age Korean language, 
this kind of transliteration method may be much more convenient and
confident way of typesetting Korean than the keyboard IM solutions.''\footnote{\url{http://www.ktug.org/xe/index.php?mid=KTUG_open_board&document_srl=240134}}

\end{document}
