Typewriter font for Korean language

With the package xeCJK you should use \setCJKmainfont to set the font for the CJK characters. The \setmainfont command is also used, but only to set the font for non-CJK characters.

MWE:

\documentclass{article}
\tracinglostchars=2
\usepackage{xeCJK}

\setCJKmainfont{Noto Sans CJK SC}
%\setCJKmonofont{Noto Sans CJK SC} optional: set separate monospace font

\begin{document}
\obeylines
00027         printf({"{}JUST A PRINT STATEMENT\(\backslash\)n"{}});
00027         printf({"{}Just a print statement\(\backslash\)n"{}});
00028         printf({"large 다음에 의해 생성됨 Doxygen 1.8.19\(\backslash\)n"{}});
\begin{verbatim}
00027         printf({"{}JUST A PRINT STATEMENT SOME MORE TEXT\(\backslash\)n"{}});
00027         printf({"{}Just a print statement some more text\(\backslash\)n"{}});
00028         printf({"large 다음에 의해 생성됨 Doxygen 1.8.19\(\backslash\)n"{}});
\end{verbatim}                                                                                                                      
\end{document}

Result:

enter image description here

Optionally, you can set a separate font for different font families, such as sans serif, math, or monospace. For monospace the command is \setCJKmonofont. See the xeCJK manual on page 6 and further for an overview of the commands for font families.


The following compiles without errors using xelatex on TeX Live 2020:

\documentclass[twoside]{book}
\tracinglostchars=2

\usepackage{xeCJK}

\defaultfontfeatures{Scale = MatchLowercase, Ligatures = TeX}
\setmainfont{Noto Sans}[Scale = 1.0]
\setmonofont{Noto Sans Mono}
%% The Noto Korean fonts can be downloaded from:
%% https://www.google.com/get/noto/help/cjk/
\setCJKmainfont{Noto Sans CJK KR}[Script=Hangul, Language=Korean]
\setCJKmonofont{Noto Sans Mono CJK KR}[Script=Hangul, Language=Korean]

\begin{document}
\obeylines
00027         printf({"{}JUST A PRINT STATEMENT\(\backslash\)n"{}});
00027         printf({"{}Just a print statement\(\backslash\)n"{}});
00028         printf({"large 다음에 의해 생성됨 Doxygen 1.8.19\(\backslash\)n"{}});
\begin{verbatim}
00027         printf({"{}JUST A PRINT STATEMENT SOME MORE TEXT SOME MORE TEXT\(\backslash\)n"{}});
00027         printf({"{}Just a print statement some more text some more text\(\backslash\)n"{}});
00028         printf({"large 다음에 의해 생성됨 Doxygen 1.8.19\(\backslash\)n"{}});
\end{verbatim}
\end{document}

You must first download the fonts you need, such as Noto Sans CJK KR. On Windows or Mac, make sure you install them as system fonts, and not just for yourself.

They are not distributed through CTAN, but you can put the files in any of the following places:

  • Install them as system fonts. On Windows or Mac, make sure to install them for all users, so XeTeX can find them.
  • Some Linux distributions package them and keep them updated. On Debian or Ubuntu, they are in the apt package fonts-noto-cjk.
  • Copy them to a local TEXMF tree. With MikTeX, you would set the environment variable TEXINPUTS= to this local directory.
  • Download them to a local folder and select them with Path=, e.g. \setCJKmonofont{NotoSansMonoCJKkr}[Path = ./customfonts , UprightFont = *-Regular , BoldFont = *-Bold , Extension = .otf] (If this is the version you downloaded.) This will break if you try to compile the document on another computer with a different version of the fonts. On the other hand, it’s the only way to be certain that you’re archiving the exact same version of the fonts, with the exact same output.
  • Put the files, or symbolic links to them, in your project directory along with your .tex files and change to that directory to compile them.
  • On Linux, you can copy fonts to a subdirectory of /usr/local/share/fonts/ to install them for everyone, or ~/.fonts/ to install them for yourself.

The reason only the Simplified Chinese fonts were working for you is that there is a CTAN package to install those.