% \iffalse meta-comment
%
% File: lxgw.dtx
% -----------------------------------------------------------------------
%   Runtime: Copyright (C) 2025-2026 by Mingyu Xia <myhsia@outlook.com> *
%                                                                       *
%   Fonts:   Copyright (C) 2021-2026 by LXGW <https://github.com/lxgw>  *
%            Copyright (C) 2021-2026 by TrionesType <x.com/TrionesType> *
% -----------------------------------------------------------------------
%   This work may be distributed and/or modified under the conditions   *
%   of the SIL Open Font License (OFL) version 1.1.                     *
%   The latest version of this license is in                            *
%                                                                       *
%       https://openfontlicense.org                                     *
%                                                                       *
%   This work has the OFL maintenance status `maintained'.              *
%                                                                       *
%   The Current Maintainer of this work on CTAN is Mingyu Xia.          *
%                                                                       *
%   The Current Designer of this font family is LXGW.                   *
% -----------------------------------------------------------------------
%   This work consists of the files lxgw.dtx,                           *
%                                   lxgw.ins,                           *
%                 the derived files ctex-fontset-lxgw.def,              *
%                                   ctex-zhmap-lxgw.tex,                *
%                                   ctex-spa-lxgw.spa,                  *
%                                   ctexpunct-lxgw.tex,                 *
%                    the font files LXGWNeoZhiSong.ttf,                 *
%                                   LXGWNeoZhiSongScreen.ttf,           *
%                                   LXGWNeoXiHei.ttf,                   *
%                                   LXGWNeoXiHeiScreen.ttf,             *
%                                   LXGWZhuqueFangsong-Regular.ttf,     *
%                                   LXGWWenKaiGBLite-Regular.ttf,       *
%                                   LXGWZhenKaiGB-Regular.ttf,          *
%           the documentation files lxgw.pdf,                           *
%                               and README.md.                          *
% -----------------------------------------------------------------------
%                                                                       *
%   Any modification of this file should ensure that the copyright and  *
%   license information is placed in the derived files.                 *
%                                                                       *
% -----------------------------------------------------------------------
%
%<*internal>
\iffalse
%</internal>
%
%<*readme>
[![CTAN Version](https://img.shields.io/ctan/v/lxgw-fonts)](https://ctan.org/pkg/lxgw-fonts)
[![GitHub Release](https://img.shields.io/github/v/release/myhsia/lxgw-ctan)](https://github.com/myhsia/lxgw-ctan/releases/latest)
[![GitHub Last Commit](https://img.shields.io/github/last-commit/myhsia/LXGW-CTAN)](https://github.com/myhsia/LXGW-CTAN/commits)
[![Actions Status](https://github.com/myhsia/lxgw-ctan/actions/workflows/main.yaml/badge.svg?branch=main)](https://github.com/myhsia/lxgw-ctan/actions)
[![GitHub Repo stars](https://img.shields.io/github/stars/myhsia/LXGW-CTAN)](https://github.com/myhsia/LXGW-CTAN)

The `LXGW` Font Family
======================

The `LXGW` Font Family provides an open-source CJK font family with a
comprehensive character set for Chinese (Simplified/Traditional), Cantonese,
and Japanese. A `fontset` configuration of this font family for the `ctex-kit`
is also provided in this package.

Issues
------

The issue tracker for `LXGW` is currently located
[on GitHub](https://github.com/myhsia/LXGW-CTAN).

Build status
------------

This project uses [GitHub Actions](https://github.com/features/actions)
as a hosted continuous integration service. For each commit, the build status
is tested using the current release of TeX Live.

_Current build status:_ ![build status](https://github.com/myhsia/lxgw-ctan/actions/workflows/main.yaml/badge.svg?branch=main)

Copyright and License
---------------------

- Runtime: Copyright (C) 2025-2026 by Mingyu Xia \<myhsia@outlook.com\>

- Fonts:   Copyright (C) 2021-2026 by [LXGW](https://github.com/lxgw) and
                                      [TrionesType](https://x.com/TrionesType)

This work may be distributed and/or modified under the conditions
of the SIL Open Font License (OFL) version 1.1.
The latest version of this license is in

    https://openfontlicense.org

This work has the OFL maintenance status `maintained'.

The Current Maintainer of this work on CTAN is **Mingyu Xia**.

The Current Designer of this font family is **LXGW** and **TrionesType**.
%</readme>
%
%<*internal>
\fi
%</internal>
%
%<*driver>
\documentclass[svgnames]{l3doc}
\usepackage[mono = false, osf]{libertine}
\usepackage[punct = plain, fontset = lxgw, scheme = plain]{ctex}
\defaultfontfeatures{Extension = .ttf, Scale = .95}
\usepackage{tikz, framed, xfrac}
\tikzset{every picture/.append style = {line cap = round}}
\ExplSyntaxOn \makeatletter
\newcommand \mail[1]{\href{mailto:#1}{\ttfamily #1}}
\dim_set:Nn \FrameSep {2pt}
\tex_tracinglostchars:D = 0
\tex_XeTeXcharclass:D "2370 = 1
\DeclareDocumentCommand \key { s m }
  {
    \IfBooleanTF {#1} { \color_select:n { red } #2 ~ }
      {
        \seq_set_from_clist:Nn \l_tmpa_seq {#2}
        \seq_set_map:NNn \l_tmpb_seq \l_tmpa_seq
          {
            \color_group_begin:
            \color_select:n { red } \exp_not:n { ##1 }
            \color_group_end:
          }
        \seq_use:Nn \l_tmpb_seq { ,~ } \:=\:
      }
  }
\cs_gset_eq:NN \val \meta
\newlist{keyval}{itemize}{10}
\setlist[keyval]{leftmargin = 0pt, labelsep = 0pt}
\def \HoLogo@LXGW#1{^^A
  \tex_XeTeXcharclass:D "004C = 1^^A L
  \tex_XeTeXcharclass:D "0058 = 1^^A X
  \tex_XeTeXcharclass:D "0047 = 1^^A G
  \tex_XeTeXcharclass:D "0057 = 1^^A W
  \kaishu LX\kern-.05emG\kern-.05emW}
\def \HoLogo@TrionesType#1{^^A
  \tex_XeTeXcharclass:D "0054 = 1^^A T
  \tex_XeTeXcharclass:D "0072 = 1^^A r
  \tex_XeTeXcharclass:D "0069 = 1^^A i
  \tex_XeTeXcharclass:D "006F = 1^^A o
  \tex_XeTeXcharclass:D "006E = 1^^A n
  \tex_XeTeXcharclass:D "0065 = 1^^A e
  \tex_XeTeXcharclass:D "0073 = 1^^A s
  \tex_XeTeXcharclass:D "0054 = 1^^A T
  \tex_XeTeXcharclass:D "0079 = 1^^A y
  \tex_XeTeXcharclass:D "0070 = 1^^A p
  \tex_XeTeXcharclass:D "0065 = 1^^A e
  \fangsong TrionesType
}
\def\@thanks{\Copyright}
\makeatother \ExplSyntaxOff
\makeindex
\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \title{The \hologo{LXGW} Font Family\thanks{^^A
%   \url{https://github.com/myhsia/LXGW-CTAN}
% }\texorpdfstring{\enspace \textbar \enspace\parbox{4em}{^^A
%     \kaishu
%     \scalebox{\fpeval{4/7}}{落霞与孤鹜齐飞}\\[-.75em]
%     \scalebox{\fpeval{4/7}}{秋水共长天一色}^^A
%   }}{}^^A
% }
%
% \author{^^A
%   Designer: \texorpdfstring{\hologo{LXGW} ({\kaishu 霞鹜})}{LXGW} /
%             \texorpdfstring{\hologo{TrionesType} ({\fangsong 璇璣造字})}
%               {TrionesType}\thanks{^^A
%     \url{https://github.com/lxgw},
%     \url{https://github.com/TrionesType/zhuque}},
%   \texorpdfstring{\enspace}{ }
%   Maintainer: Mingyu Xia\thanks{\mail{xiamingyu@westlake.edu.cn}}^^A
% }
%
% \date{Released 2026-02-07\quad \texttt{v1.521N}}
%
% \def\Copyright{^^A
%   \begin{center}
%   \setlength \fboxrule {1.2pt} \fbox{\setlength \fboxrule {.6pt}^^A
%     \fbox{\parbox {.8\linewidth} {^^A
%     This package packs a selection of open-source CJK fonts from
%     \href{https://github.com/lxgw/LxgwNeoZhiSong}
%       {\songti 霞鶩新緻宋},
%     \href{https://github.com/lxgw/LxgwNeoXiHei}
%       {\heiti 霞鶩新晰黑},
%     \href{https://github.com/lxgw/LxgwWenKaiLite}
%       {\kaishu 霞鶩文楷},
%     \href{https://github.com/lxgw/LxgwZhenKai}
%       {\kaishu \bfseries 霞鶩臻楷},
%     which are released into public domain by
%     \href{https://lxgw.github.io}{\hologo{LXGW}} and
%     \href{https://github.com/TrionesType/zhuque}
%       {\fangsong 朱雀仿宋}
%     released into public domain by
%     \href{https://x.com/TrionesType}{\hologo{TrionesType}} since 2021.
%     They are licensed under the
%     \href{https://ctan.org/license/ofl}{SIL Open Font License (OFL)}.
%   }}}
%   \end{center}}
%
% \maketitle
% \tikz[remember picture, overlay] {^^A
%   \node [ above right,     minimum width  = 1.2\ccwd,
%           inner sep = 0pt, minimum height = 1.2\ccwd,
%           rotate = -10, font = \kaishu,
%           scale = 15, opacity = .3, gray ] (xia) at
%         ([shift = {(-3 * 10pt, 2 * 10pt)}]
%           current page.south west) {驗};
%   \draw [ loosely dashed, DarkGreen, opacity = .15,
%           line width = .2 * 10pt ]
%         (xia.north west) -- (xia.south east)
%         (xia.north east) -- (xia.south west);
%   \draw [ DarkGreen, opacity = .15, line width = .2 * 10pt ]
%         (xia.north) -- (xia.south) (xia.west) -- (xia.east);
%   \draw [ rotate around = {-10:(xia.center)}, line width = .5 * 10pt,
%           DarkGreen, opacity = .1 ]
%         (xia.north west) rectangle (xia.south east);
%   \node [ right,           minimum width  = 1.2\ccwd,
%           inner sep = 0pt, minimum height = 1.2\ccwd,
%           rotate = -10, font = \kaishu,
%           scale = 15, opacity = .3, gray ] (wu) at
%         (xia.east) {訖};
%   \draw [ loosely dashed, DarkGreen, opacity = .15,
%           line width = .2 * 10pt ]
%         (wu.north west) -- (wu.south east)
%         (wu.north east) -- (wu.south west);
%   \draw [ DarkGreen, opacity = .15, line width = .2 * 10pt ]
%         (wu.north) -- (wu.south) (wu.west) -- (wu.east);
%   \draw [ rotate around = {-10:(wu.center)}, line width = .5 * 10pt,
%           DarkGreen, opacity = .1 ]
%         (wu.north west) rectangle (wu.south east);
%   \draw [ rotate around = {-10:(xia.east)}, line width = .5 * 10pt,
%           DarkGreen, opacity = .1]
%         (xia.north west) rectangle (wu.south east);
%   \node [ below left,      minimum width  = 1.2\ccwd,
%           inner sep = 0pt, minimum height = 1.2\ccwd,
%           rotate = -10, font = \fangsong,
%           scale = 15, opacity = .3, gray ] (xuan) at
%         ([shift = {(3 * 10pt, -2 * 10pt)}]
%           current page.north east) {檢};
%   \draw [ loosely dashed, DarkRed, opacity = .15,
%           line width = .2 * 10pt ]
%         (xuan.north west) -- (xuan.south east)
%         (xuan.north east) -- (xuan.south west);
%   \draw [ DarkRed, opacity = .15, line width = .2 * 10pt ]
%         (xuan.north) -- (xuan.south) (xuan.west) -- (xuan.east);
%   \draw [ rotate around = {-10:(xuan.center)},
%           line width = .5 * 10pt, DarkRed, opacity = .1 ]
%         (xuan.north west) rectangle (xuan.south east);
%   \node [ left,            minimum width  = 1.2\ccwd,
%           inner sep = 0pt, minimum height = 1.2\ccwd,
%           rotate = -10, font = \kaishu,
%           scale = 15, opacity = .3, gray ] (ji) at
%         (xuan.west) {肉};
%   \draw [ loosely dashed, DarkRed, opacity = .15,
%           line width = .2 * 10pt ]
%         (ji.north west) -- (ji.south east)
%         (ji.north east) -- (ji.south west);
%   \draw [ DarkRed, opacity = .15, line width = .2 * 10pt ]
%         (ji.north) -- (ji.south) (ji.west) -- (ji.east);
%   \draw [ rotate around = {-10:(ji.center)}, line width = .5 * 10pt,
%           DarkRed, opacity = .1 ]
%         (ji.north west) rectangle (ji.south east);
%   \draw [ rotate around = {-10:(ji.west)}, line width = .5 * 10pt,
%           DarkRed, opacity = .1]
%         (xuan.north east) rectangle (ji.south west);
% }
%
% \begin{documentation}
%
% \begin{abstract}
%   The \hologo{LXGW} Font Family provides an open-source CJK font family with a
%   comprehensive character set for Chinese (Simplified/Traditional), Cantonese,
%   and Japanese. A |fontset| configuration of this font family for the
%   \pkg{ctex-kit} is also provided in this package.
% \end{abstract}
%
% \section{Usage}
%
% Users are allowed to use the friendly interface:
% the |fontset| key in the \pkg{ctex} classes or package
% \begin{quote}
%   |\documentclass[fontset = lxgw]{ctex|^^A
%   \meta{art\textup\textbar book\textup\textbar rep\textup\textbar beamer}|}|\\
%   |\usepackage[fontset = lxgw]{ctex}|
% \end{quote}
% with \hologo{XeLaTeX}, \hologo{LuaLaTeX}, \hologo{LaTeX} + \hologo{DVIPDFMx},
% \hologo{upLaTeX} + \hologo{DVIPDFMx}, and \hologo{ApLaTeX}
% (aka \hologo{pLaTeX}-ng) supported. \hologo{pdfLaTeX} is not
% supported temporarily since the long mapping time of |zhmap|.
% Additionally, the following four commands are provided for convenience.
% \begin{function}{\songti, \heiti, \fangsong, \kaishu} \footnotesize
%   \begin{syntax}
%   \songti   宋体 (|CJKmainfont|):^^A
% \file{LXGWNeoZhiSong.ttf}, \file{LXGWNeoZhiSongScreen.ttf}\\
%   \heiti    黑体 (|CJKsansfont|):^^A
% \file{LXGWNeoXiHei.ttf}, \file{LXGWNeoXiHeiScreen.ttf}\\
%   \fangsong 仿宋 (|CJKmonofont|):^^A
% \file{LXGWZhuqueFangsong-Regular.ttf} (|AutoFakeBold| enabled)\\
%   \kaishu   楷书 (it. \kern-1.5exof |CJKmainfont|):^^A
% \file{LXGWWenKaiGBLite-Regular.ttf}, \file{LXGWZhenKaiGB-Regular.ttf}
%   \end{syntax}
% \end{function}
% This user-friendly interface is implemented in
% \ref{subsec:fontset}, \ref{subsec:spa}, and~\ref{subsec:zhmap}.
%
% The \file{.ttf} files are sourced from the following links
% \def \fetch#1{\href{#1}{\ttfamily #1}}
% \begin{itemize}[itemsep = 2pt, topsep = 4pt, leftmargin = 2em] \scriptsize
%   \item \fetch{^^A
% \iffalse
%<*fetch>
% \fi
https://github.com/lxgw/LxgwNeoZhiSong/releases/latest/download/LXGWNeoZhiSong.ttf
% \iffalse
%</fetch>
% \fi
% }
%   \item \fetch{^^A
% \iffalse
%<*fetch>
% \fi
https://github.com/lxgw/LxgwNeoXiZhi-Screen/releases/latest/download/LXGWNeoZhiSongScreen.ttf
% \iffalse
%</fetch>
% \fi
% }
%   \item \fetch{^^A
% \iffalse
%<*fetch>
% \fi
https://github.com/lxgw/LxgwNeoXiHei/releases/latest/download/LXGWNeoXiHei.ttf
% \iffalse
%</fetch>
% \fi
% }
%   \item \fetch{^^A
% \iffalse
%<*fetch>
% \fi
https://github.com/lxgw/LxgwNeoXiZhi-Screen/releases/latest/download/LXGWNeoXiHeiScreen.ttf
% \iffalse
%</fetch>
% \fi
% }
%   \item \fetch{^^A
% \iffalse
%<*fetch>
% \fi
https://github.com/TrionesType/zhuque/releases/download/v0.212/ZhuqueFangsong-v0.212.zip
% \iffalse
%</fetch>
% \fi
% }
%   \item \fetch{^^A
% \iffalse
%<*fetch>
% \fi
https://github.com/lxgw/LxgwWenkaiGB-Lite/releases/latest/download/LXGWWenKaiGBLite-Regular.ttf
% \iffalse
%</fetch>
% \fi
% }
%   \item \fetch{^^A
% \iffalse
%<*fetch>
% \fi
https://github.com/lxgw/LxgwZhenKai/releases/latest/download/LXGWZhenKaiGB-Regular.ttf
% \iffalse
%</fetch>
% \fi
% }
% \end{itemize}
%
% \section{Font Demos}
%
% The following lists the Chinese/English name, filename, and demos of the
% fonts: Cantonese, Japanese, Chinese (Simplified/Traditional) versions of
% ``\textbf{I Can Eat Glass}'', and missing character markers are provided with
% punctuation compression disabled.
% \ExplSyntaxOn
% \NewDocumentCommand \shufa { O{} m }
%   {
%     \group_begin:
%     \tl_map_inline:nn { #2 }
%       {
%         \xeCJKsetup{PunctStyle = plain, MiddlePunct+ = {，。}}
%         \tikz {
%           \node [ minimum ~ width  = 1.5\ccwd, outer ~ sep = 0pt,
%                   draw = DarkGreen!40, thick, font = #1,
%                   minimum ~ height = 1.5\ccwd, inner ~ sep = 0pt ]
%             (tmp) {##1};
%           \draw [densely ~ dashed, DarkGreen, opacity = .2]
%                 (tmp.north ~ west) -- (tmp.south ~ east)
%                 (tmp.north ~ east) -- (tmp.south ~ west);
%           \draw [DarkGreen, opacity = .2, thin]
%                 (tmp.north) -- (tmp.south) (tmp.west)  -- (tmp.east);
%         } \kern-.8pt
%       }
%     \group_end:
% }
% \ExplSyntaxOff
% \def\0{\centering
%   \shufa[\Large]{私ガラスを食べられます。^^^^2370}^^A
%   \shufa[\Large\bfseries]{それは私を傷つけません。}^^A
%   \kern.8pt \\[-.2\baselineskip+.8pt]
%   \shufa[\Large]{我能吞下玻璃而不伤身体。}^^A
%   \shufa[\Large\bfseries]{^^^^2370我能吞下玻璃而不伤身体。}^^A
%   \kern.8pt\\[-.2\baselineskip+.8pt]
%   \shufa[\Large]{我能吞下玻璃而不傷身體。}^^A
%   \shufa[\Large]{我可以食玻璃，}^^A
%   \shufa[\Large\bfseries]{佢傷唔到我。}^^A
%   \kern.8pt
% }
% \begin{keyval}
%   \item[\key*{\songti 霞鶩新緻宋 (\pkg{LXGW Neo ZhiSong})}]
%         \file{LXGWNeoZhiSong.ttf}, \file{LXGWNeoZhiSongScreen.ttf}
%   \begin{framed}
%     \songti\0
%   \end{framed}
%   \item[\key*{\heiti 霞鶩新晰黑 (\pkg{LXGW Neo XiHei})}]
%         \file{LXGWNeoXiHei.ttf}, \file{LXGWNeoXiHeiScreen.ttf}
%   \begin{framed}
%     \heiti\0
%   \end{framed}
%   \item[\key*{\fangsong 朱雀仿宋 (\pkg{\textsc{Zhuque Fangsong}})}]
%         \file{LXGWZhuqueFangsong-Regular.ttf}
%   \begin{framed}
%     \fangsong\0
%   \end{framed}
%   \item[\key*{\kaishu 霞鹜$\sfrac{\text{文楷}}{\text{臻楷}}$
%         (\pkg{LXGW $\sfrac{\text{WenKai}}{\text{ZhenKai}}$})}]
%         \file{LXGWWenKaiGBLite-Regular.ttf}, \file{LXGWZhenKaiGB-Regular.ttf}
%   \begin{framed}
%     \kaishu\0
%   \end{framed}
% \end{keyval}
% \end{documentation}
% \clearpage \appendix
% \begin{implementation}
%
% \section{The Source Code}
%
% \subsection{The \texttt{ctex-fontset-lxgw.def} file}\label{subsec:fontset}
%
% Start the optionlist |fontset| for \pkg{l3docstrip}.
%    \begin{macrocode}
%<*fontset>
%    \end{macrocode}
% Declare the \pkg{ctex-kit} font configuration file with date, version, and
% description.
%    \begin{macrocode}
\ProvidesExplFile {ctex-fontset-lxgw.def} {2026-02-07} {v1.521N}
  {lxgw fontset configuration for ctex-kit}
%    \end{macrocode}
% Load CJK font family, interface, accepts the following 4 branches,
% provided by \pkg{ctex-kit}.
%    \begin{macrocode}
\ctex_fontset_case:nnnn
%    \end{macrocode}
% \DescribeOption{\hologo{pdfTeX} (generate PDF)}
% This branch is no longer supported here, and a
% \underline{|fontset-unavailable|} error will raise.
%    \begin{macrocode}
  { \ctex_fontset_error:n { lxgw } }
%    \end{macrocode}
% \begin{texnote}
% For some fontset that supports this branch, line |4| -- |5| should be
% replaced as a line
% \begin{verbatim}
%   \ctex_fontset_case:nnn
% \end{verbatim}
% \end{texnote}
% \DescribeOption{\hologo{pdfTeX} (generate DVI)}
% For those use \hologo{LaTeX} + \hologo{DVIPDFMx}.
%    \begin{macrocode}
  {
%    \end{macrocode}
% Load the \file{.spa} file for the \pkg{CJKpunct} package.
%    \begin{macrocode}
    \ctex_file_input:n { ctexpunct-lxgw.spa }
%    \end{macrocode}
% Case choice controlled by the |zhmap| key of \pkg{ctex-kit}.
%    \begin{macrocode}
    \ctex_zhmap_case:nnn
%    \end{macrocode}
% \begin{arguments}
%   \item Content of this argument will be outputted to the input stream when
%   |zhmap = zhmCJK|
%   \begin{verbatim}[commandchars = \\\{\}]
%     \color{gray}\cs{cs_gset_eq:NN} \cs{ctex_zhmap_case:nnn} \cs{use_i:nnn}
%   \end{verbatim}
% The \hologo{LXGW} font family uses the |UniGB-UTF16-H| cmap (Character To
% Glyph Index Mapping Table).
%    \begin{macrocode}
      {
        \setCJKmainfont { LXGWNeoZhiSong.ttf              }
          [
            cmap           = UniGB-UTF16-H, AutoFakeBold,
            ItalicFont     = LXGWWenKaiGBLite-Regular.ttf,
            BoldItalicFont = LXGWZhenKaiGB-Regular.ttf
          ]
        \setCJKsansfont { LXGWNeoXiHei.ttf                }
          [ cmap = UniGB-UTF16-H, AutoFakeBold ]
        \setCJKmonofont { LXGWZhuqueFangsong-Regular.ttf  }
          [ cmap = UniGB-UTF16-H, AutoFakeBold ]
        \setCJKfamilyfont { zhsong } { LXGWNeoZhiSong.ttf             }
          [ cmap = UniGB-UTF16-H, AutoFakeBold ]
        \setCJKfamilyfont { zhhei  } { LXGWNeoXiHei.ttf               }
          [ cmap = UniGB-UTF16-H, AutoFakeBold ]
        \setCJKfamilyfont { zhfs   } { LXGWZhuqueFangsong-Regular.ttf }
          [ cmap = UniGB-UTF16-H, AutoFakeBold ]
        \setCJKfamilyfont { zhkai  } { LXGWWenKaiGBLite-Regular.ttf   }
          [ cmap = UniGB-UTF16-H, BoldFont = LXGWZhenKaiGB-Regular.ttf ]
%    \end{macrocode}
% Configure the usages of the edge information of the defined CJK families.
%    \begin{macrocode}
        \ctex_punct_set:n { lxgw }
        \ctex_punct_map_family:nn   { \CJKrmdefault         } { zhsong  }
        \ctex_punct_map_family:nn   { \CJKsfdefault         } { zhhei   }
        \ctex_punct_map_family:nn   { \CJKttdefault         } { zhfs    }
        \ctex_punct_map_bfseries:nn { \CJKrmdefault, zhsong } { zhsongb }
        \ctex_punct_map_bfseries:nn { \CJKsfdefault, zhhei  } { zhheib  }
        \ctex_punct_map_itshape:nn  { \CJKrmdefault         } { zhkai   }
      }
%    \end{macrocode}
%   \item Content of this argument will be outputted to the input stream when
%   |zhmap = true|
%   \begin{verbatim}[commandchars = \\\{\}]
%     \color{gray}\cs{cs_gset_eq:NN} \cs{ctex_zhmap_case:nnn} \cs{use_ii:nnn}
%   \end{verbatim}
%   Load the mapping file \file{ctex-zhmap-lxgw.tex} (see~\ref{subsec:zhmap})
%   for \pkg{zhmatrices} and set \cs{CJKrmdefault}, \cs{CJKsfdefault},
%   \cs{CJKttdefault}, respectively.
%    \begin{macrocode}
      {
        \ctex_load_zhmap:nnnn { rm } { zhhei } { zhfs } { lxgw }
%    \end{macrocode}
%   Configure the usages of the edge information of \cs{CJKrmdefault}.
%    \begin{macrocode}
        \ctex_punct_set:n { lxgw }
        \ctex_punct_map_family:nn   { \CJKrmdefault } { zhsong }
        \ctex_punct_map_bfseries:nn { \CJKrmdefault } { zhhei  }
        \ctex_punct_map_itshape:nn  { \CJKrmdefault } { zhkai  }
      }
%    \end{macrocode}
%   \item Content of this argument will be outputted to the input stream when
%   |zhmap = false|
%   \begin{verbatim}[commandchars = \\\{\}]
%     \color{gray}\cs{cs_gset_eq:NN} \cs{ctex_zhmap_case:nnn} \cs{use_iii:nnn}
%   \end{verbatim}
%   Here will raise a \underline{|fontset-unavailable|} error.
%    \begin{macrocode}
      { \ctex_fontset_error:n { lxgw } }
  }
%    \end{macrocode}
% \end{arguments}
% \DescribeOption{\hologo{upTeX}, \hologo{ApTeX} (aka \hologo{pTeX}-ng)}
% For those use \hologo{upLaTeX} + \hologo{DVIPDFMx}.
% Configure the basic font mapping for \hologo{upTeX}. Due to the definition in
% \pkg{zhmetrics-uptex}, configure
% \begin{multicols}{3}
% \begin{enumerate}
%   \item |upshape|  of serif font.
%   \item |bfseries| of serif font.
%   \item |itshape|  of serif font.
%   \item |upshape|  of sans font.
%   \item |bfseries| of sans font.
%   \item |upshape|  of mono font.
% \end{enumerate}
% \end{multicols}
%    \begin{macrocode}
  {
    \ctex_set_upfonts:nnnnnn
      { LXGWNeoZhiSong.ttf              }
      { LXGWNeoZhiSongScreen.ttf        }
      { LXGWWenKaiGBLite-Regular.ttf    }
      { LXGWNeoXiHei.ttf                }
      { LXGWNeoXiHeiScreen.ttf          }
      { LXGWZhuqueFangsong-Regular.ttf  }
%    \end{macrocode}
%   Config the \textsf{NFSS} font families |zhsong|, |zhhei|, |zhfs|, and
%   |zhkai| to the \textsf{JFM} name in normal type and bold type.
%   Leave empty for those font families with no bold version.
%    \begin{macrocode}
    \ctex_set_upfamily:nnn { zhsong } { upzhserif    } { upzhserifb }
    \ctex_set_upfamily:nnn { zhhei  } { upzhsans     } { upzhsans   }
    \ctex_set_upfamily:nnn { zhfs   } { upzhmono     } { }
    \ctex_set_upfamily:nnn { zhkai  } { upzhserifit  } { }
  }
%    \end{macrocode}
% \DescribeOption{\hologo{XeTeX}, \hologo{LuaTeX}}
% For those use \hologo{XeLaTeX} or \hologo{LuaLaTeX}.
%    \begin{macrocode}
  {
    \setCJKmainfont { LXGWNeoZhiSong              }
      [
        Extension      = .ttf, AutoFakeBold,
        ItalicFont     = LXGWWenKaiGBLite-Regular,
        BoldItalicFont = LXGWZhenKaiGB-Regular.ttf
      ]
    \setCJKsansfont { LXGWNeoXiHei                }
      [ Extension = .ttf, AutoFakeBold ]
    \setCJKmonofont { LXGWZhuqueFangsong-Regular  }
      [ Extension = .ttf, AutoFakeBold  ]
    \setCJKfamilyfont { zhsong } { LXGWNeoZhiSong }
      [ Extension = .ttf, AutoFakeBold ]
    \setCJKfamilyfont { zhhei  } { LXGWNeoXiHei               }
      [ Extension = .ttf, AutoFakeBold ]
    \setCJKfamilyfont { zhfs   } { LXGWZhuqueFangsong-Regular }
      [ Extension = .ttf, AutoFakeBold ]
    \setCJKfamilyfont { zhkai  } { LXGWWenKaiGBLite-Regular   }
      [ Extension = .ttf, BoldFont = LXGWZhenKaiGB-Regular ]
  }
%    \end{macrocode}
% \begin{macro}{\songti, \heiti, \fangsong, \kaishu}
% Shortcuts that same as those in the \pkg{ctex-kit}.
%    \begin{macrocode}
\NewDocumentCommand \songti   { } { \CJKfamily { zhsong } }
\NewDocumentCommand \heiti    { } { \CJKfamily { zhhei  } }
\NewDocumentCommand \fangsong { } { \CJKfamily { zhfs   } }
\NewDocumentCommand \kaishu   { } { \CJKfamily { zhkai  } }
%    \end{macrocode}
% \end{macro}
% End the optionlist |fontset| for \pkg{l3docstrip}.
%    \begin{macrocode}
%</fontset>
%    \end{macrocode}
%
% \subsection{The \texttt{ctex-spa-make.tex} and
%   the \texttt{ctexpunct-lxgw.tex} file}\label{subsec:spa}
%
% The \file{.spa} file of the corresponding font will be used
% for the \pkg{CJKpunct} package to achieve the punctuation compression,
% which can ensure the best typeset effect (under the \hologo{pdfTeX} engine).
% Run the following script, \file{ctex-spa-make.tex}, by executing
% \begin{verbatim}
%   xetex ctex-spa-make
% \end{verbatim}
% in the terminal. Then, one can obtain the \file{ctexpunct-lxgw.tex} file.
% \paragraph{Implementation of the script}
% Start the optionlist |makespa| for \pkg{l3docstrip}.
%    \begin{macrocode}
%<*makespa>
%    \end{macrocode}
% \iffalse
% Assign the module name of the variables and control sequences, which will be
% automatically replaced by \pkg{l3docstrip}.
%    \begin{macrocode}
%<@@=ctex>
%    \end{macrocode}
% \fi
% Loading the macro file \file{ctex-spa-macro.tex} provided by \pkg{ctex-kit}.
%    \begin{macrocode}
\input ctex-spa-macro %
%    \end{macrocode}
% \iffalse
% However, the macro file needs to be hacked due to the interface change
% of \hologo{XeTeX}.
%    \begin{macrocode}
\ExplSyntaxOn
\cs_set_protected:Npn \@@_write_family:nn #1#2
  {
    \group_begin:
      \tex_font:D \l_@@_punct_font = "[#2]" ~ at ~ 100 pt \scan_stop:
      \l_@@_punct_font
      \clist_clear:N \l_@@_punct_bounds_clist
      \seq_map_inline:Nn \c_@@_punct_seq
        {
          \exp_args:No \_@@_save_bounds:n
            { \int_use:N \tex_XeTeXcharglyph:D ##1 }
        }
      \iow_now:Nx \g_@@_spa_iow
        {
          \token_to_str:N \ctexspadef {#1}
            { \l_@@_punct_bounds_clist , , , }
        }
    \group_end:
  }
\ExplSyntaxOff
%    \end{macrocode}
% \fi
% List all the CJK families with the corresponding font files in terms of
% ``case-pairs''.
%    \begin{macrocode}
\MAKESPA {ctexpunct-lxgw.tex}
  {
    {lxgwzhsong}      {LXGWNeoZhiSong} ,
    {lxgwzhsongb}     {LXGWNeoZhiSongScreen} ,
    {lxgwzhhei}       {LXGWNeoXiHei} ,
    {lxgwzhheib}      {LXGWNeoXiHeiScreen} ,
    {lxgwzhfs}        {LXGWZhuqueFangsong-Regular} ,
    {lxgwzhkai}       {LXGWWenKaiGBLite-Regular} ,
    {lxgwzhkaib}      {LXGWZhenKaiGB-Regular} ,
  }
%    \end{macrocode}
% End of the script.
%    \begin{macrocode}
\primitive\end
%    \end{macrocode}
% \iffalse
% Restore the module name.
%    \begin{macrocode}
%<@@=>
%    \end{macrocode}
% \fi
% End the optionlist |zhmap| for \pkg{l3docstrip}.
%    \begin{macrocode}
%</makespa>
%    \end{macrocode}
% \iffalse
%    \begin{macrocode}
%<*lxgw-spa>
%    \end{macrocode}
%    \begin{macrocode}
\ctexspadef{lxgwzhsong}{10,8,9,8,67,8,58,8,71,8,65,9,67,8,65,10,55,5,54,4,64,9,71,9,0,0,10,10,5,72,4,71,9,77,9,77,19,69,18,69,19,70,5,50,12,12,8,71,9,65,8,67,10,65,5,55,4,53,9,64,9,71,8,10,8,9,8,67,8,58,,,}
\ctexspadef{lxgwzhsongb}{9,7,8,7,67,8,58,8,70,8,65,8,67,8,65,9,55,5,53,3,63,8,70,8,-0,-0,10,10,5,72,4,71,8,77,8,76,18,68,18,68,18,69,4,50,12,12,8,70,8,65,8,67,9,65,5,55,3,53,8,63,8,70,7,9,7,8,8,67,8,58,,,}
\ctexspadef{lxgwzhhei}{9,5,10,5,65,8,58,5,68,8,66,8,61,8,67,8,53,5,52,3,60,7,71,7,0,0,11,11,4,72,6,67,8,77,9,77,19,69,18,69,20,69,4,48,8,8,8,68,8,66,8,61,8,67,6,53,3,52,7,60,7,71,5,9,5,10,8,65,5,58,,,}
\ctexspadef{lxgwzhheib}{9,5,9,5,64,8,57,5,68,8,65,7,61,8,67,8,53,5,52,3,60,6,70,6,0,0,11,11,4,72,6,67,8,77,9,77,19,69,17,69,20,69,4,47,8,8,8,67,7,65,8,61,8,67,5,53,3,52,6,60,6,70,5,9,5,9,8,64,5,57,,,}
\ctexspadef{lxgwzhfs}{3,2,3,2,60,8,60,5,65,16,62,17,63,18,59,17,60,13,49,12,60,6,69,8,0,0,11,11,12,64,12,62,17,66,11,76,19,69,16,68,20,66,15,58,20,18,18,63,17,62,18,63,17,59,13,60,11,49,7,59,8,69,2,3,2,3,12,56,8,57,,,}
\ctexspadef{lxgwzhkai}{12,11,6,4,72,6,68,5,72,6,71,7,72,6,68,7,66,5,52,5,70,-1,72,4,0,0,12,12,7,71,8,65,10,77,12,76,20,70,18,70,17,72,7,50,12,12,6,72,7,71,6,72,7,68,5,66,5,52,-1,70,4,72,11,12,4,6,6,72,5,68,,,}
\ctexspadef{lxgwzhkaib}{6,8,6,8,71,4,64,5,71,5,70,6,71,5,67,6,65,4,47,4,62,3,66,3,-1,-1,10,10,7,67,4,65,14,67,16,68,17,68,14,67,16,71,6,49,11,11,5,71,6,70,5,71,6,67,4,65,4,47,3,62,3,66,8,6,8,6,4,71,5,64,,,}
%    \end{macrocode}
%    \begin{macrocode}
%</lxgw-spa>
%    \end{macrocode}
% \fi
%
% \subsection{The \texttt{ctex-zhmap-lxgw.tex} file}\label{subsec:zhmap}
%
% Start the optionlist |zhmap| for \pkg{l3docstrip}.
%    \begin{macrocode}
%<*zhmap>
%    \end{macrocode}
% Forked from the |zhmap| optionlist of \file{ctex.dtx}\footnote{^^A
%   \url{https://github.com/CTeX-org/ctex-kit/blob/master/ctex/ctex.dtx}}.
%
%    \begin{macrocode}
\begingroup\catcode61\catcode48\catcode32=10\relax%
  \catcode 35=6  % #
  \catcode 45=12 % -
  \catcode123=1  % {
  \catcode125=2  % }
  \toks0{\endlinechar=\the\endlinechar\relax}%
  \toks2{\endlinechar=-1 }%
  \def\x#1 #2 {%
    \toks0\expandafter{\the\toks0 \catcode#1=\the\catcode#1\relax}%
    \toks2\expandafter{\the\toks2 \catcode#1=#2 }}%
  \x  13  5 % carriage return
  \x  32 10 % space
  \x  35  6 % #
  \x  40 12 % (
  \x  41 12 % )
  \x  45 12 % -
  \x  46 12 % .
  \x  47 12 % /
  \x  58 12 % :
  \x  60 12 % <
  \x  61 12 % =
  \x  64 11 % @
  \x  91 12 % [
  \x  93 12 % ]
  \x 123  1 % {
  \x 125  2 % }
  \edef\x#1{\endgroup%
    \edef\noexpand#1{%
      \the\toks0 %
      \let\noexpand\noexpand\noexpand#1%
          \noexpand\noexpand\noexpand\undefined%
      \noexpand\noexpand\noexpand\endinput}%
    \the\toks2}%
\expandafter\x\csname ctex@zhmap@endinput\endcsname
\begingroup\expandafter\endgroup
\expandafter\let\csname ifzhmappdf\expandafter\endcsname\csname
  \expandafter\ifx\csname ifctexpdf\endcsname\relax
    \expandafter\ifx\csname pdfoutput\endcsname\relax
      iffalse\else\ifnum\pdfoutput < 1 iffalse\else iftrue\fi\fi
  \else ifctexpdf\fi
\endcsname
\begingroup
\expandafter\ifx\csname ProvidesFile\endcsname\relax
  \long\def\x#1\ProvidesFile#2[#3]{%
    #1%
    \immediate\write-1{File: #2 #3}%
    \expandafter\xdef\csname ver@#2\endcsname{#3}}
  \expandafter\x%
\fi
\endgroup
%    \end{macrocode}
% Provides the identification information of the font map loader.
%    \begin{macrocode}
\ProvidesFile{ctex-zhmap-lxgw.tex}%
  [2026-02-07 v1.521N lxgw font map loader for DVIPDFMx (CTEX)]
%    \end{macrocode}
% Font map loader for \hologo{pdfTeX} (generate PDF) is disabled since
% \hologo{pdfTeX} maps too slowly.
%    \begin{macrocode}
\ifzhmappdf
%    \end{macrocode}
% \iffalse
%    \begin{macrocode}
\iffalse
  \pdfmapline{=gbk@UGBK@          <LXGWNeoZhiSong.ttf}
  \pdfmapline{=gbksong@UGBK@      <LXGWNeoZhiSong.ttf}
  \pdfmapline{=gbkkai@UGBK@       <LXGWWenKaiGBLite-Regular.ttf}
  \pdfmapline{=gbkhei@UGBK@       <LXGWNeoXiHei.ttf}
  \pdfmapline{=gbkfs@UGBK@        <LXGWZhuqueFangsong-Regular.ttf}
  \pdfmapline{=cyberb@Unicode@    <LXGWNeoZhiSong.ttf}
  \pdfmapline{=unisong@Unicode@   <LXGWNeoZhiSong.ttf}
  \pdfmapline{=unikai@Unicode@    <LXGWWenKaiGBLite-Regular.ttf}
  \pdfmapline{=unihei@Unicode@    <LXGWNeoXiHei.ttf}
  \pdfmapline{=unifs@Unicode@     <LXGWZhuqueFangsong-Regular.ttf}
  \pdfmapline{=gbksongsl@UGBK@    <LXGWNeoZhiSong.ttf}
  \pdfmapline{=gbkkaisl@UGBK@     <LXGWWenKaiGBLite-Regular.ttf}
  \pdfmapline{=gbkheisl@UGBK@     <LXGWNeoXiHei.ttf}
  \pdfmapline{=gbkfssl@UGBK@      <LXGWZhuqueFangsong-Regular.ttf}
  \pdfmapline{=unisongsl@Unicode@ <LXGWNeoZhiSong.ttf}
  \pdfmapline{=unikaisl@Unicode@  <LXGWWenKaiGBLite-Regular.ttf}
  \pdfmapline{=uniheisl@Unicode@  <LXGWNeoXiHei.ttf}
  \pdfmapline{=unifssl@Unicode@   <LXGWZhuqueFangsong-Regular.ttf}
\fi
%    \end{macrocode}
% \fi
% Configuration for \hologo{pdfTeX} (generate DVI).
%    \begin{macrocode}
\else
%    \end{macrocode}
% Configure the upright shape of \cs{songti}, \cs{kaishu}, \cs{heiti},
% and \cs{fangsong} mapping for GBK encoding and UTF8 encoding.
%    \begin{macrocode}
\special{pdf:mapline gbk@UGBK@          UniGB-UTF16-H LXGWNeoZhiSong.ttf}
\special{pdf:mapline gbksong@UGBK@      UniGB-UTF16-H LXGWNeoZhiSong.ttf}
\special{pdf:mapline gbkkai@UGBK@       UniGB-UTF16-H LXGWWenKaiGBLite-Regular.ttf}
\special{pdf:mapline gbkhei@UGBK@       UniGB-UTF16-H LXGWNeoXiHei.ttf}
\special{pdf:mapline gbkfs@UGBK@        UniGB-UTF16-H LXGWZhuqueFangsong-Regular.ttf}
\special{pdf:mapline cyberb@Unicode@    UniGB-UTF16-H LXGWNeoZhiSong.ttf}
\special{pdf:mapline unisong@Unicode@   UniGB-UTF16-H LXGWNeoZhiSong.ttf}
\special{pdf:mapline unikai@Unicode@    UniGB-UTF16-H LXGWWenKaiGBLite-Regular.ttf}
\special{pdf:mapline unihei@Unicode@    UniGB-UTF16-H LXGWNeoXiHei.ttf}
\special{pdf:mapline unifs@Unicode@     UniGB-UTF16-H LXGWZhuqueFangsong-Regular.ttf}
%    \end{macrocode}
% Similar for the (fake) slant shape, set the
% \emph{Afine Transformation coefficient} to |0.167|, which is the same as the
% default value of |AutoFakeSlant| in the \pkg{xeCJK} package.
%    \begin{macrocode}
\special{pdf:mapline gbksongsl@UGBK@    UniGB-UTF16-H LXGWNeoZhiSong.ttf -s .167}
\special{pdf:mapline gbkkaisl@UGBK@     UniGB-UTF16-H LXGWWenKaiGBLite-Regular.ttf -s .167}
\special{pdf:mapline gbkheisl@UGBK@     UniGB-UTF16-H LXGWNeoXiHei.ttf -s .167}
\special{pdf:mapline gbkfssl@UGBK@      UniGB-UTF16-H LXGWZhuqueFangsong-Regular.ttf -s .167}
\special{pdf:mapline unisongsl@Unicode@ UniGB-UTF16-H LXGWNeoZhiSong.ttf -s .167}
\special{pdf:mapline unikaisl@Unicode@  UniGB-UTF16-H LXGWWenKaiGBLite-Regular.ttf -s .167}
\special{pdf:mapline uniheisl@Unicode@  UniGB-UTF16-H LXGWNeoXiHei.ttf -s .167}
\special{pdf:mapline unifssl@Unicode@   UniGB-UTF16-H LXGWZhuqueFangsong-Regular.ttf -s .167}
\fi
%    \end{macrocode}
% End the optionlist |zhmap| for \pkg{l3docstrip}.
%    \begin{macrocode}
%</zhmap>
%    \end{macrocode}
% \end{implementation}
% \clearpage
% \PrintIndex
