diff options
Diffstat (limited to 'macros/luatex/generic/luatexko')
-rw-r--r-- | macros/luatex/generic/luatexko/ChangeLog | 17 | ||||
-rw-r--r-- | macros/luatex/generic/luatexko/README | 2 | ||||
-rw-r--r-- | macros/luatex/generic/luatexko/luatexko-doc.pdf | bin | 326736 -> 338396 bytes | |||
-rw-r--r-- | macros/luatex/generic/luatexko/luatexko-doc.tex | 179 | ||||
-rw-r--r-- | macros/luatex/generic/luatexko/luatexko-normalize.lua | 4 | ||||
-rw-r--r-- | macros/luatex/generic/luatexko/luatexko-uhc2utf8.lua | 4 | ||||
-rw-r--r-- | macros/luatex/generic/luatexko/luatexko.lua | 195 | ||||
-rw-r--r-- | macros/luatex/generic/luatexko/luatexko.sty | 344 |
8 files changed, 457 insertions, 288 deletions
diff --git a/macros/luatex/generic/luatexko/ChangeLog b/macros/luatex/generic/luatexko/ChangeLog index 87afc21887..07a26993c6 100644 --- a/macros/luatex/generic/luatexko/ChangeLog +++ b/macros/luatex/generic/luatexko/ChangeLog @@ -1,3 +1,20 @@ +2021-06-10 Dohyun Kim <nomos at ktug org> + + Version 3.2 + + * luatexko.lua: + - support automatic josa selection after hanja characters + - dotemph/uline/ruby routines are now called from hpack_filter, + pre_linebreak_filter, and post_linebreak_filter callbacks. + + * luatexko.sty: + - use LaTeX's selectfont hook which require LaTeX 2021/06/01 or later + - a new LaTeX environment: verticaltypesetting + - new plain TeX commands: \sethangulfont \sethanjafont \setfallbackfont + \beginverticaltypesetting \endverticaltypesetting + - vertical/horizontal environments now honor empty argument, which means + natural width. + 2021-04-20 Dohyun Kim <nomos at ktug org> Version 3.1 diff --git a/macros/luatex/generic/luatexko/README b/macros/luatex/generic/luatexko/README index 1b9329ffca..f3e1feb636 100644 --- a/macros/luatex/generic/luatexko/README +++ b/macros/luatex/generic/luatexko/README @@ -1,4 +1,4 @@ -LuaTeX-ko Package version 3.1 (2021/04/20) +LuaTeX-ko Package version 3.2 (2021/06/10) =========================================== This is a Lua(La)TeX macro package that supports typesetting Korean diff --git a/macros/luatex/generic/luatexko/luatexko-doc.pdf b/macros/luatex/generic/luatexko/luatexko-doc.pdf Binary files differindex dc87222ab2..7b4c4336e6 100644 --- a/macros/luatex/generic/luatexko/luatexko-doc.pdf +++ b/macros/luatex/generic/luatexko/luatexko-doc.pdf diff --git a/macros/luatex/generic/luatexko/luatexko-doc.tex b/macros/luatex/generic/luatexko/luatexko-doc.tex index d23b010e8f..9153b572ed 100644 --- a/macros/luatex/generic/luatexko/luatexko-doc.tex +++ b/macros/luatex/generic/luatexko/luatexko-doc.tex @@ -41,7 +41,6 @@ } } \defaultfontfeatures+{Renderer=HarfBuzz} -\setmainfont{Latin Modern Roman}[Expansion] % for hb tlig \setmainhangulfont{Noto Serif CJK KR}[ Scale=0.98, AutoFakeSlant, @@ -50,9 +49,9 @@ UprightFont=* Light, BoldFont=* Bold, InterLatinCJK=.125em, + CompressPunctuations, Expansion, Protrusion=notoserifcjk, ] -\setsansfont{Latin Modern Sans} \setsanshangulfont{Noto Sans CJK KR}[ Scale=0.98, Script=Hangul, @@ -74,7 +73,8 @@ CharRaise=-.125ex, Color=MidnightBlue, ] -\setmathhangulfont{Noto Sans CJK KR}[ +\setmathhangulfont{Noto Sans CJK KR} +[ Script=Hangul, Language=Korean, SizeFeatures={ @@ -110,7 +110,7 @@ \AddToHook{env/itemize/begin}{\small} \AddToHook{env/verbatim/begin}{\linespread{1.1}} -\catcode`|=13 \protected\def|{\verb|\let\\=\textbackslash} +\catcode`|=13 \protected\def|{\verb|\let\\=\textbackslash} %| \def\nohyphen{\language\csname l@nohyphenation\endcsname} \protected\def\cs#1{\texttt{\nohyphen \textbackslash\detokenize{#1}}} \protected\def\pkgkwd#1#{\leavevmode @@ -125,6 +125,14 @@ \def\kotex{\logoko\kern-.1ex .\kern-.1667em \TeX} \def\hemph#1{\textsf{\bfseries #1}} \def\ldots{$\dots$} +\newenvironment{plaintex}{% + \par\bigskip + \begin{narrower}\small\parindent=0pt + \leavevmode\llap{\color{gray}plain \TeX\quad}\ignorespaces +}{ + \par + \end{narrower}% +} \widowpenalty5000 \clubpenalty5000 @@ -134,7 +142,7 @@ \author{Dohyun Kim \normalsize |<nomos at ktug org>| \and Soojin Nam \normalsize |<jsunam at gmail com>| \and \normalsize <\url{http://github.com/dohyunkim/luatexko}>} -\date{Version 3.1\quad 2021/04/20} +\date{Version 3.2\quad 2021/06/10} \maketitle \begin{quote} @@ -181,13 +189,7 @@ fontspec 문서 참조. 첫 두 줄, 즉 main/sans 글꼴들에는 |Ligatures=TeX| 옵션이 자동으로 주어진다.% \footnote{% \cs{adhochangulfont} \cs{adhochanjafont} \cs{addhocfallbackfont}는 - 마지막 줄 명령들의 다른 이름들이다. }\,% -\footnote{% - 플레인텍에서 한글 글꼴 설정은 다음과 같이 한다:\par - \leftskip=3em\noindent - \cs{hangulfont=UnDotum\relax}\\ - \cs{hanjafont=UnDotum at 14pt}\\ - \cs{fallbackfont=HanaMinB at 12pt} } + 마지막 줄 명령들의 다른 이름들이다. } \begin{verbatim} \setmainhangulfont \setmainhanjafont \setmainfallbackfont \setsanshangulfont \setsanshanjafont \setsansfallbackfont @@ -198,6 +200,27 @@ fontspec 문서 참조. \hangulfontspec \hanjafontspec \fallbackfontspec \end{verbatim} +\begin{plaintex} + 플레인텍에서 한글 글꼴 설정은 다음과 같이 할 수 있다: +\begin{verbatim} + \hangulfont=UnDotum\relax + \hanjafont="Noto Sans CJK KR" at 10pt + \fallbackfont=HanaMinA at 10pt +\end{verbatim} + + v3.2부터는 한글폰트의 기본값으로 \hemph{은바탕}을 로드한다. + 또한 다음 명령들도 제공한다: +\begin{verbatim} + \sethangulfont\taza=UnTaza at 12pt + \sethanjafont\dotum=UnDotum at 12pt + \setfallbackfont\noto={Noto Sans CJK KR} at 12pt +\end{verbatim} + 그리하여 다음처럼 지시할 수 있게 된다: +\begin{verbatim} + \expandafter\def\expandafter\tt\expandafter{\tt\taza\dotum\noto} +\end{verbatim} +\end{plaintex} + \section{글꼴 대체}\label{sec:fontswitch} 원칙적으로 \luatexko는 지시된 글자가 영문폰트에 없으면 한글폰트에서, @@ -219,15 +242,15 @@ fontspec 문서 참조. |0|을 지시해야 이 기능이 비로소 꺼진다. verbatim 코드를 식자할 때는 이 기능이 작동하지 않으며,% \footnote{% - 정확히 말하자면 |\\language=\\l@nohyphenation|, 즉 하이프네이션이 - 허용 안 되는 상황에서는 작동하지 않는다. + 정확히 말하자면 |\\language=\\l@nohyphenation| (플레인텍에서는 |\\language=-1|인 경우), + 즉 하이프네이션이 허용 안 되는 상황에서는 작동하지 않는다. 부연하건대, |\\language=\\l@nohyphenation| 상황에서 작동하지 않는 그밖의 기능은 다음과 같다: 줄바꿈 허용, InterCharacter, InterHangul, InterLatinCJK, CompressPunctuations, RemoveClassicSpaces, 한글^^b7한자 폰트 문자 다음의 공백 크기 조정 등. 마지막의 한글^^b7한자 다음의 공백 크기 조정은 영문자가 고정폭 글꼴일 때에도 작동하지 않는다. } -문장부호가 고정폭 글꼴일 때에도 작동하지 않는다. +문장부호가 고정폭 글꼴이거나 tfm 폰트일 때에도 작동하지 않는다. 영향 받는 문장부호들의 기본값은 다음과 같다: \begin{verbatim} [0x21] ! [0x27] ' [0x28] ( [0x29] ) @@ -374,7 +397,9 @@ fontspec의 글꼴 옵션 외에 \luatexko가 따로 제공하는 것들이 있 |Vertical=HalfMetrics|와 거의 같은 기능을 한다.% \footnote{% 플레인텍에서는 각각 |+halt| 및 |+vhal|이다. 이들과 완전 동일하진 - 않다. 가령 U+3002 (\char"3002) 처리의 경우.} + 않다. 가령 U+00B7\;(^^b7)의 경우 및 고문헌조판 모드에서 + U+2018\;(^^^^2018) U+2019\;(^^^^2019) U+201C\;(^^^^201c) U+201D\;(^^^^201d) + 처리의 경우.} \item[Protrusion] \pkgkwd*{Protrusion}% 특정 글자가 행 끝에 왔을 때 판면 바깥으로 끌어내는 @@ -417,12 +442,16 @@ fontspec의 글꼴 옵션 외에 \luatexko가 따로 제공하는 것들이 있 }\label{fig:gomun} \end{figure} -고문헌 조판을 위해 \pkgkwd{typesetclassic} 환경을 제공한다.% +고문헌 조판을 위해 \pkgkwd{typesetclassic} 환경을 제공한다. +전처리부에 \cs{typesetclassic}을 선언할 수도 있다.% \footnote{% 플레인텍에서는 (문서 전체에 적용하지 않는다면 그룹 안에서) - \cs{typesetclassic}을 사용한다. + \cs{typesetclassic}을 사용한다. }\,% +\footnote{% |japanese|, |chinese|, |Schinese|, |Tchinese|, |korean| 따위의 환경은 - 지난 버전과의 호환성을 위해 당분간 제공되고 있을 뿐이다. } + 지난 버전과의 호환성을 위해 제공되고 있을 뿐이다. + 그렇더라도 중국어나 일본어 폰트를 사용한다면 이들 환경을 사용하는 것이 좋다. + |chinese|는 |Schinese|와 동의어이다. } 그림~\ref{fig:gomun} 참조. v2.0부터는 고문헌 조판에서 한글^^b7한자와 영문자가 붙어 나오더라도 자동으로 @@ -464,6 +493,13 @@ v2.0부터는 고문헌 조판에서 한글^^b7한자와 영문자가 붙어 나 세로쓰기에서 |CharRaise| 옵션의 효과에 대해서는 제\ref{sec:fontoption}절을 참조. +문서의 일부를 세로쓰기하려면 +|\begin{|\pkgkwd{vertical}|}{<dimen>}| \ldots\ |\end{vertical}| +환경을 이용한다. 인자 |<dimen>|으로 세로쓰기 박스의 높이를 지시한다. +그림~\ref{fig:vertical},~\ref{fig:vertical3} 및 \ref{fig:vertical2} 참조. +만약 인자가 비어있거나 \cs{empty}이면 본문을 한 줄짜리 박스로 식자하며, +이때 높이는 natural height가 된다. + \begin{figure} \fboxsep=5pt \framebox[\linewidth]{ @@ -472,7 +508,9 @@ v2.0부터는 고문헌 조판에서 한글^^b7한자와 영문자가 붙어 나 \hunmintxt \end{vertical} } - \caption{세로쓰기의 예. 박스 높이 |20em|을 지시했다.}\label{fig:vertical} + \caption{세로쓰기의 예. 박스 높이 |20em|을 지시했다. + 아직 HarfBuzz 모드를 쓸 수 없으므로 폰트에 |Renderer=Node| 옵션을 명시했다. + }\label{fig:vertical} \end{figure} \begin{figure} @@ -494,24 +532,6 @@ v2.0부터는 고문헌 조판에서 한글^^b7한자와 영문자가 붙어 나 }\label{fig:vertical3} \end{figure} -문서의 일부를 세로쓰기하려면 -|\begin{|\pkgkwd{vertical}|}{<dimen>}| \ldots\ |\end{vertical}| -환경을 이용한다. |<dimen>|으로 세로쓰기 박스의 높이를 지시한다.% -\footnote{% - 플레인텍에서는 \cs{vertical{<dimen>}} \ldots\ \cs{endvertical}. } -그림~\ref{fig:vertical},~\ref{fig:vertical3} 및 \ref{fig:vertical2} 참조. - -문서 전체를 세로쓰기한다면 이 환경을 쓰는 대신 -\pkgkwd{\verticaltypesetting} 명령을 전처리부에 선언한다. -이때 면주는 가로로 식자되며 면주 폰트의 설정은 사용자의 몫이다. - -세로쓰기 도중에 문서의 일부를 가로쓰기하려면 -|\begin{|\pkgkwd{horizontal}|}{<dimen>}| \ldots\ |\end{horizontal}| -환경을 이용한다. |<dimen>|은 가로쓰기 박스의 너비를 지시한다.% -\footnote{% - 플레인텍에서는 \cs{horizontal{<dimen>}} \ldots\ \cs{endhorizontal}. } -가로쓰기 영역의 폰트 설정은 사용자의 몫이다. - \begin{figure} \fboxsep=5pt \framebox[\linewidth]{ @@ -541,6 +561,33 @@ v2.0부터는 고문헌 조판에서 한글^^b7한자와 영문자가 붙어 나 }\label{fig:vertical2} \end{figure} +문서 전체를 세로쓰기한다면 이 환경을 쓰는 대신 +\pkgkwd{\verticaltypesetting} 명령을 전처리부에 선언한다. +이때 면주는 가로로 식자되며 면주 폰트의 설정은 사용자의 몫이다. + +몇몇 페이지를 세로쓰기로 식자하려면 본문 중에 +|\begin{|\pkgkwd{verticaltypesetting}|}| \ldots\ |\end{verticaltypesetting}| +환경을 이용한다. +이때도 면주는 가로로 식자되며, 환경의 시작과 끝에서 쪽나눔이 행해진다. + +세로쓰기 도중에 문서의 일부를 가로쓰기하려면 +|\begin{|\pkgkwd{horizontal}|}{<dimen>}| \ldots\ |\end{horizontal}| +환경을 이용한다. |<dimen>|은 가로쓰기 박스의 너비를 지시한다. +만약 인자가 비어있거나 \cs{empty}이면 본문을 한 줄짜리 박스로 식자하며, +이때 너비는 당연히 natural width가 된다. + +\begin{plaintex} + 문서의 일부를 세로쓰기하려면 |\vertical{<dimen>}| \ldots\ |\endvertical|. + 인자는 비워둘 수 있다. + + 문서 전체를 세로쓰기하려면 문서 첫머리에 \cs{verticaltypesetting}. + + 몇몇 페이지를 세로쓰기하려면 \cs{beginverticaltypesetting} \ldots\ \cs{endverticaltypesetting}. + + 세로쓰기 도중에 가로쓰기를 넣으려면 |\horizontal{<dimen>}| \ldots\ |\endhorizontal|. + 인자는 비워둘 수 있다. +\end{plaintex} + \section{드러냄표}\label{sec:dotemph} \pkgkwd{\dotemph} 명령으로 \dotemph{드러냄표}% @@ -575,9 +622,7 @@ v2.0부터는 고문헌 조판에서 한글^^b7한자와 영문자가 붙어 나 \footnote{% 플레인텍에서는 루비의 글꼴크기를 따로 조정해주지 않는다. 사용자가 \cs{rubyfont}를 설정할 때 크기도 함께 지시하도록 한다. - 가령:\par - \leftskip=3em\noindent - |\\font\\rubyfont=UnBatang at \\rubysize em| } + 가령: |\\font\\rubyfont=UnBatang at \\rubysize em| } ③~|\def|\pkgkwd{\rubysep}|{0.1ex}|: 루비와 본문 글자 사이의 간격을 지정 @@ -635,12 +680,12 @@ ulem 패키지가 \luatexko와 궁합이 맞지 않아{\small (줄바꿈에 문 \begin{verbatim} \def\ymarker{% \markoverwith{% - \hbox{{\color{yellow!50}\vrule width 1pt height 9pt depth 2pt}}% + \hbox{\color{yellow!50}\vrule width 1pt height 9pt depth 2pt}% }} \end{verbatim} \def\ymarker{\markoverwith{% - \hbox{{\color{yellow!50}\vrule width 1pt height 9pt depth 2pt}}}} + \hbox{\color{yellow!50}\vrule width 1pt height 9pt depth 2pt}}} \cs{ymarker{노란색을 칠해서 강조한다}}\quad$\Rightarrow$\quad \ymarker{노란색을 칠해서 강조한다}. @@ -679,23 +724,26 @@ ulem 패키지가 \luatexko와 궁합이 맞지 않아{\small (줄바꿈에 문 수식 한글 폰트를 설정하면 수식 모드에서도 한글을 {\small(hbox로 감싸지 않고)} 직접 입력할 수 있다.% \footnote{% - 플레인텍에서는 \cs{mathhangulfont=UnBatang}과 같이 설정한다. - 또는 좀 더 그럴듯하게 하려면:\par - \leftskip=3em\noindent - |\\font\\texthangul="Noto Sans CJK KR DemiLight" at 10pt|\\ - |\\font\\scripthangul="Noto Sans CJK KR Regular" at 7pt|\\ - |\\font\\scriptscripthangul="Noto Sans CJK KR Medium" at 5pt|\\ - |\\setmathhangulfonts\\texthangul\\scripthangul\\scriptscripthangul| } + |\\hbox|를 쓰지 않고 직접 입력하는 수식 한글이 + \uline{디스플레이 수식} 안에 사용된 경우, + 앞서 기술한 드러냄표 강조, 밑줄 강조, 한글 글꼴 옵션 등의 기능이 현재로는 + 전혀 작동하지 않는다. 구현은 비교적 간단하지만, 과연 수식에서 + 저러한 기능을 써야 할 경우가 있을까 의문이기 때문이다. + 사용자의 요청이 있으면 즉시 반영하겠다. +} v2.0부터는 자동으로 수식 한글을 잡아주지 않는다.% \pkgkwd*{\setmathhangulfont} \begin{verbatim} - \setmathhangulfont{Noto Sans CJK KR}[ + \setmathhangulfont{Noto Sans CJK KR} + [ SizeFeatures={ {Size=-6, Font=* Medium}, {Size=6-9, Font=* Regular}, {Size=9-, Font=* DemiLight}, - } ] + } + ] \end{verbatim} + 현재 한글만 쓸 수 있게 설정되어 있다. 한자도 수식에 직접 입력하려면 사용자는 다음 명령으로 유니코드 블럭을 추가 지정해야 한다.% \pkgkwd*{\setmathhangulblock} @@ -703,6 +751,18 @@ v2.0부터는 자동으로 수식 한글을 잡아주지 않는다.% \setmathhangulblock{4E00}{9FC3} \end{verbatim} +\begin{plaintex} + 플레인텍에서는 \cs{mathhangulfont=UnBatang}과 같이 설정한다. + + 또는 좀 더 그럴듯하게 하려면: +\begin{verbatim} + \font\texthangul="Noto Sans CJK KR DemiLight" at 10pt + \font\scripthangul="Noto Sans CJK KR Regular" at 7pt + \font\scriptscripthangul="Noto Sans CJK KR Medium" at 5pt + \setmathhangulfonts\texthangul\scripthangul\scriptscripthangul +\end{verbatim} +\end{plaintex} + \section{한국어 항목 번호}\label{sec:hangulnums} \kotex과 동일하게 항목 번호를 한국어 기호로 붙일 수 있다.% @@ -719,7 +779,9 @@ v2.0부터는 자동으로 수식 한글을 잡아주지 않는다.% 유사하다.% \footnote{% 변환기능은 |lua-uni-algos| 패키지를 이용하므로 - 이 패키지를 설치해두어야 한다. 또한 HarfBuzz 모드에서는 + 이 패키지를 설치해두어야 한다. }\,% +\footnote{% + HarfBuzz 모드에서는 첫가끝 자모로의 입력변환이 효과를 못볼 수도 있으니 유의할 것. } @@ -732,7 +794,8 @@ v2.0부터는 자동으로 수식 한글을 잡아주지 않는다.% |0|을 할당하면 다시 UTF-8 입력으로 간주한다. \XeTeX의 \cs{XeTeXinputencoding} 명령과 유사하나, 오직 한국어 문자만 처리할 수 있다.% \footnote{% - 윈도 운영체제에서의 한글 파일이름 불러오기 기능은 v2.0부터는 제공하지 않는다. + CP949 인코딩 파일시스템을 사용하는 윈도 운영체제에서의 + 한글 파일이름 불러오기 기능은 v2.0부터는 제공하지 않는다. 대신 |luatex -cmdx ...|, |lualatex -cmdx ...|와 같이 컴파일시 명령행에 |-cmdx| 옵션을 주면 된다고 하니 테스트해 보시기 바란다. } @@ -743,6 +806,14 @@ v2.0부터는 자동으로 수식 한글을 잡아주지 않는다.% \section*{주요 변경 이력} \begin{itemize}\linespread{1.1}\selectfont + \item[v3.2] ------ + \item 한자 뒤에서도 자동조사 기능이 대체로 동작하게끔 하였다. + \XeTeX-\logoko{} 패키지가 설치돼 있을 것을 요구한다. + \item \hyperref[sec:verttype]{|vertical| 및 |horizontal| 환경의 인자를 비워둘 수 있다}. + \item \hyperref[sec:verttype]{|verticaltypesetting|을 환경으로도 쓸 수 있다. + 플레인텍에서는 \cs{beginverticaltypesetting} \cs{endverticaltypesetting}}. + \item \hyperref[sec:fontcmds]{플레인텍 명령 + \cs{sethangulfont} \cs{sethanjafont} \cs{setfallbackfont} 추가} \item[v3.0] ------ \item \hyperref[sec:fontoption]{세로쓰기에서 |CharRaise| 옵션은 이제 글자들의 \dotemph{추가적인} 이동 길이를 나타낸다.} diff --git a/macros/luatex/generic/luatexko/luatexko-normalize.lua b/macros/luatex/generic/luatexko/luatexko-normalize.lua index a86b709390..96a0d12cf3 100644 --- a/macros/luatex/generic/luatexko/luatexko-normalize.lua +++ b/macros/luatex/generic/luatexko/luatexko-normalize.lua @@ -13,8 +13,8 @@ luatexbase.provides_module({ name = "luatexko-normalize", - version = "3.1", - date = "2021/04/20", + version = "3.2", + date = "2021/06/10", author = "Dohyun Kim, Soojin Nam", description = "Hangul normalization", license = "LPPL v1.3+", diff --git a/macros/luatex/generic/luatexko/luatexko-uhc2utf8.lua b/macros/luatex/generic/luatexko/luatexko-uhc2utf8.lua index d3d86fcb25..2c5fd64f9e 100644 --- a/macros/luatex/generic/luatexko/luatexko-uhc2utf8.lua +++ b/macros/luatex/generic/luatexko/luatexko-uhc2utf8.lua @@ -13,8 +13,8 @@ luatexbase.provides_module({ name = "luatexko-uhc2utf8", - version = "3.1", - date = "2021/04/20", + version = "3.2", + date = "2021/06/10", author = "Dohyun Kim, Soojin Nam", description = "UHC (CP949) input encoding", license = "LPPL v1.3+", diff --git a/macros/luatex/generic/luatexko/luatexko.lua b/macros/luatex/generic/luatexko/luatexko.lua index d0360a8b72..aa1aa4149f 100644 --- a/macros/luatex/generic/luatexko/luatexko.lua +++ b/macros/luatex/generic/luatexko/luatexko.lua @@ -13,8 +13,8 @@ luatexbase.provides_module { name = 'luatexko', - date = '2021/04/20', - version = '3.1', + date = '2021/06/10', + version = '3.2', description = 'typesetting Korean with LuaTeX', author = 'Dohyun Kim, Soojin Nam', license = 'LPPL v1.3+', @@ -72,6 +72,7 @@ local attributes = luatexbase.attributes local call_callback = luatexbase.call_callback local create_callback = luatexbase.create_callback local module_warning = luatexbase.module_warning +local new_attribute = luatexbase.new_attribute local new_user_whatsit = luatexbase.new_user_whatsit local registernumber = luatexbase.registernumber @@ -85,6 +86,7 @@ local glueid = node.id"glue" local glyphid = node.id"glyph" local hlistid = node.id"hlist" local kernid = node.id"kern" +local localparid = node.id"local_par" local mathid = node.id"math" local penaltyid = node.id"penalty" local ruleid = node.id"rule" @@ -98,6 +100,7 @@ local italcorr = 3 local lua_number = 100 local lua_value = 108 local spaceskip = 13 +local indentbox = 3 local nohyphen = registernumber"l@nohyphenation" or -1 -- verbatim local langkor = registernumber"koreanlanguage" or 16383 @@ -107,11 +110,12 @@ local fallbackfontattr = attributes.luatexkofallbackfontattr local autojosaattr = attributes.luatexkoautojosaattr local classicattr = attributes.luatexkoclassicattr local dotemphattr = attributes.luatexkodotemphattr -local ulineattr = attributes.luatexkoulineattr local rubyattr = attributes.luatexkorubyattr local hangulbyhangulattr = attributes.luatexkohangulbyhangulattr local hanjabyhanjaattr = attributes.luatexkohanjabyhanjaattr +local unicodeattr = new_attribute"luatexkounicodeattr" + local stretch_f = 5/100 -- should be consistent for ruby local function get_font_data (fontid) @@ -537,12 +541,15 @@ local special_classes = { [0xFF01] = 4, [0xFF1A] = 2, [0xFF1B] = 2, [0xFF1F] = 4, }, { __index = charclass }), setmetatable({ -- TC - [0x3001] = 3, [0x3002] = 3, [0xFF0C] = 3, [0xFF0E] = 3, + [0x3001] = 3, [0x3002] = 5, [0xFF0C] = 3, [0xFF0E] = 5, }, { __index = charclass }), setmetatable({ -- TC vert - [0x3001] = 3, [0x3002] = 3, [0xFF0C] = 3, [0xFF0E] = 3, + [0x3001] = 3, [0x3002] = 5, [0xFF0C] = 3, [0xFF0E] = 5, [0xFF1A] = 7, [0xFF1B] = 7, -- 0xFE13, 0xFE14 }, { __index = charclass }), + setmetatable({ -- JP vert + [0xFF1B] = 7, -- 0xFE14 + }, { __index = charclass }), } local function get_char_class (c, classic) @@ -684,8 +691,8 @@ local function process_fonts (head) while curr do local id = curr.id if id == glyphid then - local props = my_node_props(curr) - if not props.unicode then + if curr.font ~= 0 -- exclude nullfont + and not has_attribute(curr, unicodeattr) then local c = curr.char @@ -735,7 +742,7 @@ local function process_fonts (head) end end - props.unicode = c + set_attribute(curr, unicodeattr, c) end elseif id == discid then curr.pre = process_fonts(curr.pre) @@ -779,11 +786,11 @@ local function hbox_char_font (box, init, glyfonly) while curr do local id = curr.id if id == glyphid then - local c = my_node_props(curr).unicode or curr.char + local c = has_attribute(curr, unicodeattr) or curr.char if c and not is_cjk_combining(c) then return c, curr.font end - elseif id == hlistid and curr.list then + elseif curr.list then return hbox_char_font(curr, init, glyfonly) elseif not glyfonly and is_blocking_node(curr) then return @@ -858,7 +865,7 @@ local function process_linebreak (head, par) while curr do local id = curr.id if id == glyphid then - local c = my_node_props(curr).unicode or curr.char + local c = has_attribute(curr, unicodeattr) or curr.char if c and not is_unicode_var_sel(c) then local old = has_attribute(curr, classicattr) head, pc, pcl = maybe_linebreak(head, curr, pc, pcl, c, old, curr.font, par) @@ -913,7 +920,7 @@ local function process_interhangul (head, par) while curr do local id = curr.id if id == glyphid then - local c = my_node_props(curr).unicode or curr.char + local c = has_attribute(curr, unicodeattr) or curr.char if c and not is_unicode_var_sel(c) then head, pc = do_interhangul_option(head, curr, pc, c, curr.font, par) @@ -975,7 +982,7 @@ local function process_interlatincjk (head, par) while curr do local id = curr.id if id == glyphid then - local c = my_node_props(curr).unicode or curr.char + local c = has_attribute(curr, unicodeattr) or curr.char if c and not is_unicode_var_sel(c) then head, pc, pf, pcl = do_interlatincjk_option(head, curr, pc, pf, pcl, c, curr.font, par) pc = breakable_after[c] and pc or 0 @@ -1033,7 +1040,7 @@ local function process_glyph_width (head) if curr.lang ~= nohyphen and fontoptions.compresspunctuations[curr.font] then - local cc = my_node_props(curr).unicode or curr.char + local cc = has_attribute(curr, unicodeattr) or curr.char local old = has_attribute(curr, classicattr) local class = get_char_class(cc, old) if class >= 1 and class <= 4 and @@ -1087,11 +1094,11 @@ local function process_remove_spaces (head) local vchar, vfont if id == glyphid and v.lang ~= nohyphen then - local c = my_node_props(v).unicode or v.char or 0 + local c = has_attribute(v, unicodeattr) or v.char or 0 if is_unicode_var_sel(c) then v = getprev(v) or v end - vchar, vfont = my_node_props(v).unicode or v.char, v.font + vchar, vfont = has_attribute(v, unicodeattr) or v.char, v.font elseif id == hlistid and v.list then vchar, vfont = hbox_char_font(v, k == "n") end @@ -1131,6 +1138,23 @@ local josa_table = { [0xC774] = {0xC774, nil, 0xC774}, -- 이(라) = 이, , 이 } +local hanja2hangul = { } + +local function add_to_hanja2hangul (filename, i, last) + local f = kpse.find_file(filename) + if f then + for c in io.lines(f) do + hanja2hangul[i] = tonumber(c) + i = i + 1 + end + else + warning("cannot find %s", filename) + for c = i, last do + hanja2hangul[c] = c + end + end +end + local josa_code = setmetatable({ [0x30] = 3, [0x31] = 1, [0x33] = 3, [0x36] = 3, [0x37] = 1, [0x38] = 1, [0x4C] = 1, [0x4D] = 3, @@ -1156,16 +1180,37 @@ local josa_code = setmetatable({ [0xFF13] = 3, [0xFF16] = 3, [0xFF17] = 1, [0xFF18] = 1, [0xFF2C] = 1, [0xFF2D] = 3, [0xFF2E] = 3, [0xFF4C] = 1, [0xFF4D] = 3, [0xFF4E] = 3, -},{ __index = function(_,c) +},{ __index = function(t, cc) + local c = cc + -- xetexko에 포함된 .tab 파일들을 이용해 한자를 한글로 변환 + if c >= 0x4E00 and c <= 0x9FA5 then + if not hanja2hangul[c] then + add_to_hanja2hangul("hanja_hangul.tab", 0x4E00, 0x9FA5) + end + c = hanja2hangul[c] + elseif c >= 0xF900 and c <= 0xFA2D then + if not hanja2hangul[c] then + add_to_hanja2hangul("hanjacom_hangul.tab", 0xF900, 0xFA2D) + end + c = hanja2hangul[c] + elseif c >= 0x3400 and c <= 0x4DB5 then + if not hanja2hangul[c] then + add_to_hanja2hangul("hanjaexa_hangul.tab", 0x3400, 0x4DB5) + end + c = hanja2hangul[c] + end if is_hangul(c) then c = (c - 0xAC00) % 28 + 0x11A7 end if is_chosong(c) then - return c == 0x1105 and 1 or 3 + c = c == 0x1105 and 1 or 3 + t[cc] = c; return c elseif is_jungsong(c) then - return c ~= 0x1160 and 2 + c = c ~= 0x1160 and 2 + t[cc] = c; return c elseif is_jongsong(c) then - return c == 0x11AF and 1 or 3 + c = c == 0x11AF and 1 or 3 + t[cc] = c; return c elseif is_noncjk_char(c) and c <= 0x7A or c >= 0x2160 and c <= 0x217F -- roman or c >= 0x2460 and c <= 0x24E9 -- ① @@ -1175,11 +1220,13 @@ local josa_code = setmetatable({ or c >= 0xFF10 and c <= 0xFF19 -- 0 or c >= 0xFF21 and c <= 0xFF3A -- A or c >= 0xFF41 and c <= 0xFF5A -- a - then return 2 + then + t[cc] = 2; return 2 elseif c >= 0x3131 and c <= 0x314E or c >= 0x3165 and c <= 0x3186 -- ㄱ or c >= 0x3200 and c <= 0x320D -- ㈀ or c >= 0x3260 and c <= 0x326D -- ㉠ - then return 3 + then + t[cc] = 3; return 3 end end }) @@ -1188,7 +1235,7 @@ local function prevjosacode (n, parenlevel, ignore_parens) while n do local id = n.id if id == glyphid then - local c = my_node_props(n).unicode or n.char -- beware hlist/vlist + local c = has_attribute(n, unicodeattr) or n.char -- beware hlist/vlist if ignore_parens and c == 0x29 then -- ) parenlevel = parenlevel + 1 elseif ignore_parens and c == 0x28 then -- ( @@ -1287,8 +1334,8 @@ local function process_dotemph (head) elseif curr.id == glyphid then local dotattr = has_attribute(curr, dotemphattr) - if dotattr then - local c = my_node_props(curr).unicode or curr.char + if dotattr and dotemphbox[dotattr] then + local c = has_attribute(curr, unicodeattr) or curr.char if is_hangul(c) or is_compat_jamo(c) or is_chosong(c) or @@ -1425,7 +1472,7 @@ end local ulitems = {} local function process_uline (head, parent, level) - local curr, level, attr = head, level or 0 + local curr, level = head, level or 0 while curr do if curr.list then curr.list = process_uline(curr.list, curr, level+1) @@ -1439,33 +1486,28 @@ local function process_uline (head, parent, level) list = list, subtype = subtype, level = level, + start = getnext(curr) or curr, } else local item = ulitems[value] if item then head = draw_uline(head, curr, parent, item, true) ulitems[value] = nil - attr = nil end end - else - local currattr = has_attribute(curr, ulineattr) - if currattr then - local item = ulitems[currattr] - if item and not item.start then - item.start = curr - attr = currattr - end - end + local to_free = curr + head, curr = noderemove(head, curr) + nodefree(to_free) + goto nextnode end curr = getnext(curr) + ::nextnode:: end - if attr then - local item = ulitems[attr] - if item and item.level == level then + for _, item in pairs(ulitems) do + if item.level == level then head = draw_uline(head, nodeslide(head), parent, item) item.start = nil end @@ -1496,13 +1538,23 @@ local function process_ruby_pre_linebreak (head) local rubyid = has_attribute(curr, rubyattr) if rubyid then local ruby_t = rubybox[rubyid] - if ruby_t[3] then -- rubyoverlap + if ruby_t and ruby_t[3] then -- rubyoverlap local side = (ruby_t[1].width - curr.width)/2 if side > 0 then -- ruby is wide local k, r = nodenew(kernid), nodenew(ruleid) k.subtype, k.kern = userkern, -side r.width, r.height, r.depth = side, 0, 0 local k2, r2 = nodecopy(k), nodecopy(r) + + local prev = curr.prev -- 문단 첫머리에 루비 돌출 방지 + if prev then + if prev.id == localparid or + prev.id == hlistid and prev.subtype == indentbox and prev.width == 0 + then + k.kern = 0 + end + end + head = insert_before(head, curr, k) head = insert_before(head, curr, r) head, curr = insert_after(head, curr, r2) @@ -1540,17 +1592,19 @@ local function process_ruby_post_linebreak (head) -- consider charraise local shift = shift_put_top(curr, ruby) - local _, f = hbox_char_font(curr, true, true) - local ascender = tableunpack(fontoptions.asc_desc[f]) or curr.height - ruby.shift = shift - ascender - ruby.depth - ruby_t[2] -- rubysep + local f, ascender, descender + _, f = hbox_char_font(curr, true, true) + ascender = fontoptions.asc_desc[f][1] or curr.height + _, f = hbox_char_font(ruby, true, true) + descender = fontoptions.asc_desc[f][2] or ruby.depth + + ruby.shift = shift - ascender - descender - ruby_t[2] -- rubysep head = insert_before(head, curr, ruby) end - ruby_t = nil - elseif curr.list then - curr.list = process_ruby_post_linebreak(curr.list) + rubybox[rubyid] = nil end - elseif curr.list then - curr.list = process_ruby_post_linebreak(curr.list) + elseif id == mathid then + curr = end_of_math(curr) end curr = getnext(curr) end @@ -1600,7 +1654,7 @@ local function process_reorder_tonemarks (head) fontoptions.is_not_harf[curr.font] and fontoptions.is_hangulscript[curr.font] then - local uni = my_node_props(curr).unicode or curr.char + local uni = has_attribute(curr, unicodeattr) or curr.char if is_hangul(uni) or is_chosong(uni) or uni == 0x25CC then init = curr elseif is_jungsong(uni) or is_jongsong(uni) then @@ -1609,7 +1663,7 @@ local function process_reorder_tonemarks (head) local n, syllable = init, { init = init } while n do if n.id == glyphid then - local u = my_node_props(n).unicode or n.char + local u = has_attribute(n, unicodeattr) or n.char if u then tableinsert(syllable, u) end end if n == curr then break end @@ -1912,7 +1966,7 @@ end -- charraise -local raiseattr = luatexbase.new_attribute"luatexkoraiseattr" +local raiseattr = new_attribute"luatexkoraiseattr" local function process_charraise (head) local curr = head @@ -1957,7 +2011,7 @@ local function process_fake_slant_corr (head) -- for font fallback tableinsert(t, char_in_font(p.font, p.char).italic or 0) end - local c = my_node_props(p).unicode or p.char + local c = has_attribute(p, unicodeattr) or p.char if is_jungsong(c) or is_jongsong(c) or hangul_tonemark[c] then else break @@ -2034,13 +2088,6 @@ end, local pass_fun = function(...) return ... end create_callback("luatexko_prelinebreak_first", "data", pass_fun) create_callback("luatexko_prelinebreak_second", "data", pass_fun) -create_callback("luatexko_do_atbegshi", "data", pass_fun) - -function luatexko.process_atbegshi (box) - if box and box.list then - box.list = call_callback("luatexko_do_atbegshi", box.list) - end -end add_to_callback("pre_shaping_filter", function(h, gc) local par = gc == "" @@ -2250,14 +2297,20 @@ otfregister { local auxiliary_procs = { dotemph = { - luatexko_do_atbegshi = process_dotemph, + post_linebreak_filter = process_dotemph, + hpack_filter = process_dotemph, }, uline = { - luatexko_do_atbegshi = process_uline, + post_linebreak_filter = function(h) return process_uline(h) end, + hpack_filter = function(h) return process_uline(h) end, }, ruby = { - pre_linebreak_filter = process_ruby_pre_linebreak, - luatexko_do_atbegshi = process_ruby_post_linebreak, + pre_linebreak_filter = function(h) + h = process_ruby_pre_linebreak(h) + h = process_ruby_post_linebreak(h) + return h + end, + hpack_filter = process_ruby_post_linebreak, }, autojosa = { luatexko_prelinebreak_first = process_josa, @@ -2267,9 +2320,16 @@ local auxiliary_procs = { }, } +-- dotemph 등을 수식 한글에서도 작동하게 하려면 +-- post_mlist_to_hlist_filter 콜백을 이용해야 한다. + function luatexko.activate (name) for cbnam, cbfun in pairs( auxiliary_procs[name] ) do - add_to_callback(cbnam, cbfun, "luatexko."..cbnam.."."..name) + local prior + if cbnam == "hpack_filter" then + prior = luatexbase.priority_in_callback(cbnam, "luaotfload.color_handler") or nil + end + add_to_callback(cbnam, cbfun, "luatexko."..cbnam.."."..name, prior) end active_processes[name] = true end @@ -2281,8 +2341,9 @@ function luatexko.deactivateall (str) for _, name in ipairs{ "pre_shaping_filter", "post_shaping_filter", "pre_linebreak_filter", + "hpack_filter", "hyphenate", - "luatexko_do_atbegshi", -- might not work properly + "post_linebreak_filter", } do local t = {} for i, v in ipairs( luatexbase.callback_descriptions(name) ) do @@ -2304,7 +2365,3 @@ function luatexko.reactivateall () luatexko.deactivated = nil end -function luatexko.currenthashangulchars (cnt) - texcount[cnt] = char_in_font(fontcurrent(), 0xAC00) and 1 or 0 -end - diff --git a/macros/luatex/generic/luatexko/luatexko.sty b/macros/luatex/generic/luatexko/luatexko.sty index c44ccedcbe..b3f78f4ba4 100644 --- a/macros/luatex/generic/luatexko/luatexko.sty +++ b/macros/luatex/generic/luatexko/luatexko.sty @@ -12,9 +12,9 @@ % version 2006/05/20 or later. \ifdefined\luatexkohangulfontattr \endinput\fi -\ifdefined\selectfont - \NeedsTeXFormat{LaTeX2e}[2020/10/01] - \ProvidesPackage{luatexko}[2021/04/20 v3.1 typesetting Korean with LuaTeX] +\ifdefined\ProvidesPackage + \NeedsTeXFormat{LaTeX2e}[2021/06/01] + \ProvidesPackage{luatexko}[2021/06/10 v3.2 typesetting Korean with LuaTeX] \RequirePackage{luatexbase} \RequirePackage{fontspec}[2020/02/03] \else @@ -25,52 +25,43 @@ \catcode`\@=11 \fi \newlanguage\koreanlanguage -\protected\def\pdfliteral{\pdfextension literal} \newattribute\luatexkohangulfontattr \newattribute\luatexkohanjafontattr \newattribute\luatexkofallbackfontattr \newattribute\luatexkoautojosaattr \newattribute\luatexkoclassicattr \newattribute\luatexkodotemphattr -\newattribute\luatexkoulineattr \newattribute\luatexkorubyattr \chardef\luatexkorubyalloc\allocationnumber \newattribute\luatexkohangulbyhangulattr \newattribute\luatexkohanjabyhanjaattr \directlua{ require"luatexko" } -\ifdefined\AtBegShi@Hook - \edef\AtBegShi@Hook{% occupy the first position - \unexpanded{% - \AtBegShi@Item{% - \directlua{% - luatexko.process_atbegshi(tex.getbox(\the\AtBeginShipoutBox)) - }% - }% - }% - \unexpanded\expandafter{\AtBegShi@Hook}% - } -\else - \AddToHook{shipout/before}{% - \directlua{ luatexko.process_atbegshi(tex.getbox(\the\ShipoutBox)) }% - } - \DeclareHookRule{shipout/before}{.}{before}{luacolor} -\fi -% classic -\protected\def\typesetclassic{% 0 +% classics +% 0: horizontal KO, JP +% 1: vertical KO, SC +% 2: horizontal SC +% 3: horizontal TC +% 4: vertical TC +% 5: vertical JP +\chardef\luatexkolangCJK=\z@ % 0:KO, 1:JP, 2:SC, 3:TC +\protected\def\typesetclassic{% \ifnum\luatexkoclassicattr<\z@ \luatexkoclassicattr\z@ \parindent1em \fi } -\protected\def\typesetvertical{% 1 - \ifcase\luatexkoclassicattr +\protected\def\typesetvertical{% 1, 4, 5 + \ifcase\luatexkolangCJK \luatexkoclassicattr\@ne \parindent1em \or + \luatexkoclassicattr=5\relax + \parindent1em \or \luatexkoclassicattr\@ne + \parindent2em \or \luatexkoclassicattr=4\relax - \or + \parindent2em \else \luatexkoclassicattr\@ne \parindent1em @@ -78,7 +69,25 @@ } \protected\def\typesetmodern{\unsetattribute\luatexkoclassicattr} \protected\def\inhibitglue{\hskip\z@skip} +\protected\def\japanese{% 0, 5 + \chardef\luatexkolangCJK=\@ne + \ifcase\luatexkoclassicattr + \or + \luatexkoclassicattr=5\relax + \or + \luatexkoclassicattr\z@ + \or + \luatexkoclassicattr\z@ + \or + \luatexkoclassicattr=5\relax + \or + \else + \luatexkoclassicattr\z@ + \fi + \parindent1em + } \protected\def\Schinese{% 2, 1 + \chardef\luatexkolangCJK=\tw@ \ifcase\luatexkoclassicattr \luatexkoclassicattr\tw@ \or @@ -87,12 +96,15 @@ \luatexkoclassicattr\tw@ \or \luatexkoclassicattr\@ne + \or + \luatexkoclassicattr\@ne \else \luatexkoclassicattr\tw@ \fi \parindent2em } \protected\def\Tchinese{% 3, 4 + \chardef\luatexkolangCJK=\thr@@ \ifcase\luatexkoclassicattr \luatexkoclassicattr\thr@@ \or @@ -101,12 +113,14 @@ \luatexkoclassicattr\thr@@ \or \or + \or + \luatexkoclassicattr=4\relax \else \luatexkoclassicattr\thr@@ \fi \parindent2em } -\let\korean\typesetmodern \let\japanese\typesetclassic \let\chinese\Schinese +\let\korean\typesetmodern \let\chinese\Schinese % josa \count@"AC00 \loop @@ -189,19 +203,16 @@ % dotemph \newcount\luatexkodotemphcount \def\dotemphraise{1ex } -\unless\ifdefined\bfseries\let\bfseries\bf\fi -\def\dotemphchar{\bfseries\char"02D9 } +\edef\dotemphchar{\expandafter\noexpand\ifdefined\bfseries\bfseries\else\bf\fi ^^^^02d9} \protected\def\dotemph#1{% \global\advance\luatexkodotemphcount\@ne + \ifnum\luatexkodotemphcount=\@ne \directlua{ luatexko.activate"dotemph" }\fi \begingroup + \count@=\luatexkodotemphcount \setbox\z@\hbox{\raise\dotemphraise\hbox{\dotemphchar}}% - \directlua{ - if \the\luatexkodotemphcount == 1 then luatexko.activate("dotemph") end - luatexko.dotemphbox[\the\luatexkodotemphcount] = node.copy(tex.box[0]) - }\luatexkodotemphattr\luatexkodotemphcount #1% - \directlua{ - luatexko.dotemphboundary(\the\luatexkodotemphattr) - }% + \directlua{ luatexko.dotemphbox[\number\count@] = node.copy(tex.box[0]) }% + \luatexkodotemphattr\count@ #1\relax + \directlua{ luatexko.dotemphboundary(\number\count@) }% \endgroup } % uline \newcount\luatexkoulinecount @@ -215,19 +226,15 @@ \luatexkomarkoverwith } \def\luatexkomarkoverwith#1#2{% \global\advance\luatexkoulinecount\@ne + \ifnum\luatexkoulinecount=\@ne \directlua{ luatexko.activate"uline" }\fi \begingroup + \count@=\luatexkoulinecount \leavevmode \setbox\z@\hbox{#1}% - \directlua{ - if \the\luatexkoulinecount == 1 then luatexko.activate("uline") end - luatexko.ulboundary(\the\luatexkoulinecount, - tex.box[0].list, - \luatexkoleaderstype) - }% - \luatexkoulineattr\luatexkoulinecount #2\relax - \directlua{ - luatexko.ulboundary(\the\luatexkoulineattr) - }\endgroup } + \directlua{ luatexko.ulboundary(\number\count@, tex.box[0].list, \luatexkoleaderstype) }% + #2\relax + \directlua{ luatexko.ulboundary(\number\count@) }% + \endgroup } \protected\def\uline{\markoverwith{% \vrule width\z@ height-\ulinedown depth\dimexpr\ulinedown+\ulinewidth\relax }} \protected\def\dashuline{\markoverwith*{% @@ -271,15 +278,16 @@ \let\rubynooverlap\ruby@overlapfalse \rubyoverlap % ruby may hangover neighboring chars \newcount\luatexkorubycount -\def\luatexkorubybasehbox{\hbox attr\luatexkorubyalloc=\luatexkorubycount} \protected\def\ruby#1#2{% \global\advance\luatexkorubycount\@ne + \ifnum\luatexkorubycount=\@ne \directlua{ luatexko.activate"ruby" }\fi \begingroup + \count@=\luatexkorubycount \leavevmode - \setbox\z@\luatexkorubybasehbox{#1}% base + \setbox\z@\hbox attr\luatexkorubyalloc=\count@{#1}% base \setbox\tw@\hbox{% ruby \ifdefined\rubyfont \rubyfont \fi - \ifdefined\selectfont % <- latex + \ifcsname ver@luatexko.sty\endcsname % <- latex \dimen@\dimexpr\rubysize em\relax \fontsize\dimen@\dimen@\selectfont \fi @@ -291,13 +299,13 @@ \ifruby@overlap \dimen@\dimexpr\wd\tw@-\wd\z@-\dimen@ii\relax % overhang .5 rubysize \ifdim\dimen@ > \z@ - \setbox\z@\luatexkorubybasehbox spread\dimen@{% + \setbox\z@\hbox attr\luatexkorubyalloc=\count@ spread\dimen@{% \hskip\z@ plus \luatexkostretchfactor em\relax \unhbox\z@ \hskip\z@ plus \luatexkostretchfactor em\relax }% \fi \else - \setbox\z@\luatexkorubybasehbox to\wd\tw@{% + \setbox\z@\hbox attr\luatexkorubyalloc=\count@ to\wd\tw@{% \hskip\z@ plus \luatexkostretchfactor em\relax \unhbox\z@ \hskip\z@ plus \luatexkostretchfactor em\relax }% @@ -316,8 +324,7 @@ \fi \fi \directlua{ - if \the\luatexkorubycount == 1 then luatexko.activate("ruby") end - luatexko.rubybox[\the\luatexkorubycount] = { + luatexko.rubybox[\number\count@] = { node.copy(tex.box[2]), \number\numexpr\dimexpr\rubysep\relax\relax, \ifruby@overlap true\else false\fi, }}% @@ -337,56 +344,62 @@ % vertical writing \protected\def\vertical#1{% \leavevmode - \setbox\z@\vbox\bgroup - \hsize#1\relax - \typesetvertical } + \ifx\empty#1\empty + \setbox\z@\hbox\bgroup + \else + \setbox\z@\vbox\bgroup \hsize#1\relax + \fi + \typesetvertical } \protected\def\endvertical{% \egroup \luatexkorotatebox\z@ \box\z@ } \protected\def\luatexkorotatebox#1{% - \setbox#1\hbox to\dimexpr\ht#1+\dp#1{% + \dimen@\dimexpr\ht#1+\dp#1\relax + \setbox#1\hbox to\dimen@\bgroup \hfil - \vbox to\wd#1{% - \wd#1\z@ \ht#1\z@ \dp#1\z@ - \pdfliteral{q 0 -1 1 0 0 0 cm}\box#1\pdfliteral{Q}% - \vfil }}} + \vbox to\wd#1\bgroup + \wd#1\z@ + \pdfextension save\relax + \pdfextension setmatrix{0 -1 1 0}\relax + \box#1\relax + \kern-\dimen@ + \pdfextension restore\relax + \vfil + \egroup + \egroup +} % horizontal box inside vertical writing \def\luatexkohorizboxmoveright{0.5ex} \protected\def\horizontal#1{% \directlua{ luatexko.gethorizboxmoveright() }% \leavevmode - \setbox\z@\vbox\bgroup - \hsize#1\relax - \typesetmodern } + \ifx\empty#1\empty + \setbox\z@\hbox\bgroup + \else + \setbox\z@\vbox\bgroup \hsize#1\relax + \fi + \typesetmodern } \protected\def\endhorizontal{% \egroup - \dimen@=\dimexpr.5\wd\z@-\luatexkohorizboxmoveright\relax \luatexkounrotatebox\z@ - \lower\dimen@\box\z@ } + \raise\luatexkohorizboxmoveright + \box\z@ } \protected\def\luatexkounrotatebox#1{% - \setbox#1\hbox to\dimexpr\ht#1+\dp#1{% - \vbox to\wd#1{% + \dimen@\dimexpr\ht#1+\dp#1\relax + \setbox#1\hbox to\dimen@\bgroup + \lower.5\wd#1\vbox to\wd#1\bgroup \vfil - \wd#1\z@ \ht#1\z@ \dp#1\z@ - \pdfliteral{q 0 1 -1 0 0 0 cm}\box#1\pdfliteral{Q}}% - \hfil }} -% do not veticalize headline/footline -\ifdefined\selectfont - \def\verticaltypesetting{% - \maxdepth\z@ \typesetvertical - \dimen@\textwidth \textwidth\textheight \textheight\dimen@ - \edef\@outputpage{\unexpanded{\luatexkorotatebox\@outputbox - \textwidth\textheight}\unexpanded\expandafter{\@outputpage}}} -\else - \def\verticaltypesetting{% - \dimen@\hsize \hsize\vsize \vsize\dimen@ - \edef\plainoutput{\unexpanded{\dimen@\hsize \hsize\vsize \vsize\dimen@}% - \unexpanded\expandafter{\plainoutput}}% - \def\pagebody{\setbox\z@\vbox to\hsize{\boxmaxdepth=\maxdepth - \pagecontents}\luatexkorotatebox\z@\box\z@}% - \maxdepth\z@ \typesetvertical } -\fi + \wd#1\z@ + \pdfextension save\relax + \pdfextension setmatrix{0 1 -1 0}\relax + \box#1\relax + \kern-\dimen@ + \pdfextension restore\relax + \egroup + \hfil + \egroup +} % hangul normalize \def\luatexhangulnormalize{% \directlua{require"luatexko-normalize"}% @@ -443,16 +456,51 @@ \fi \fi } % plain -\ifdefined\selectfont\else +\ifcsname ver@luatexko.sty\endcsname\else + % do not verticalize headline/footline. + \def\verticaltypesetting{% + \dimen@\hsize \hsize\vsize \vsize\dimen@ + \edef\plainoutput{\dimen@\hsize \hsize\vsize \vsize\dimen@ + \unexpanded\expandafter{\plainoutput}}% + \def\pagebody{\setbox\z@\vbox to\hsize{\boxmaxdepth=\maxdepth \pagecontents}% + \luatexkorotatebox\z@\box\z@}% + \maxdepth\z@ \typesetvertical + \let\verticaltypesetting\relax % prevent multiple running + } + \def\beginverticaltypesetting{\vfill\supereject \begingroup \verticaltypesetting} + \def\endverticaltypesetting{\vfill\supereject \endgroup} + % hangul fonts \protected\def\hangulfont{% \afterassignment\luatexkohangulselectfont\font\luatexkohangulfont} \protected\def\hanjafont{% \afterassignment\luatexkohanjaselectfont\font\luatexkohanjafont} \protected\def\fallbackfont{% \afterassignment\luatexkofallbackselectfont\font\luatexkofallbackfont} - \newfam\symmathhangul + \def\sethangulfont#1{% + \def\@tempa{#1}\edef\@tempb{\csstring#1}% + \expandafter\afterassignment\expandafter\luatexko@sethangulfont + \expandafter\font\csname luatexko.hangulfont.\@tempb\endcsname } + \def\luatexko@sethangulfont{% + \expandafter\protected\expandafter\edef\@tempa{% + \luatexkohangulfontattr\fontid\csname luatexko.hangulfont.\@tempb\endcsname\relax }} + \def\sethanjafont#1{% + \def\@tempa{#1}\edef\@tempb{\csstring#1}% + \expandafter\afterassignment\expandafter\luatexko@sethanjafont + \expandafter\font\csname luatexko.hanjafont.\@tempb\endcsname } + \def\luatexko@sethanjafont{% + \expandafter\protected\expandafter\edef\@tempa{% + \luatexkohanjafontattr\fontid\csname luatexko.hanjafont.\@tempb\endcsname\relax }} + \def\setfallbackfont#1{% + \def\@tempa{#1}\edef\@tempb{\csstring#1}% + \expandafter\afterassignment\expandafter\luatexko@setfallbackfont + \expandafter\font\csname luatexko.fallbackfont.\@tempb\endcsname } + \def\luatexko@setfallbackfont{% + \expandafter\protected\expandafter\edef\@tempa{% + \luatexkofallbackfontattr\fontid\csname luatexko.fallbackfont.\@tempb\endcsname\relax }} + \hangulfont={UnBatang:mode=node;script=hang;+tlig} at 10pt % default: unbatang \protected\def\setmathhangulfonts#1#2#3{% font identifiers - \ifnum\Umathcharfam"AC00=\symmathhangul\else + \ifnum\Umathcodenum"AC00="AC00\relax + \csname newfam\endcsname\symmathhangul \setmathhangulblock{AC00}{D7A3}% \fi \textfont\symmathhangul=#1\relax @@ -471,17 +519,41 @@ \catcode`\@=\luatexkoatcatcode \endinput\fi % latex -\IfHookExistsTF{selectfont}{ - \AddToHook{selectfont}{% - \luatexkohangulselectfont - \luatexkohanjaselectfont - \luatexkofallbackselectfont } -}{ - \RequirePackage{everysel} - \EverySelectfont{% - \luatexkohangulselectfont - \luatexkohanjaselectfont - \luatexkofallbackselectfont } +% do not verticalize headline/footline +\def\verticaltypesetting{% + \ifx\@nodocument\relax % not in the preamble + \clearpage + \begingroup + \fi + \hsize\textheight \vsize\textwidth + \textwidth\hsize \textheight\vsize + \@colroom\vsize \@colht\vsize + \if@twocolumn + \columnwidth=.5\dimexpr\textwidth-\columnsep\relax + \linewidth\columnwidth \hsize\columnwidth + \else + \linewidth\hsize \columnwidth\hsize + \fi + \expandafter\def\expandafter\@outputpage\expandafter{% + \expandafter\luatexkorotatebox\expandafter\@outputbox + \expandafter\textwidth\expandafter\textheight + \@outputpage + }% + \maxdepth\z@ \typesetvertical + \let\verticaltypesetting\relax % prevent multiple running +} +\def\endverticaltypesetting{% + \clearpage + \endgroup + \global\@colroom\textheight + \global\@colht\textheight + \global\vsize\textheight +} +% hangul fonts +\AddToHook{selectfont}{% + \luatexkohangulselectfont + \luatexkohanjaselectfont + \luatexkofallbackselectfont } \AddToHook{rmfamily}{% \let\luatexkohangulfont \luatexkomainhangulfont @@ -505,26 +577,9 @@ } % fontspec-like \ExplSyntaxOn -\cs_new_nopar:Npn \l_luatexko_silent_upshape { - \tl_map_inline:nn { \mddefault \bfdefault } - { - \cs_if_exist:cF - { \g_fontspec_encoding_tl/\l_fontspec_family_tl/##1/\updefault } - { - \cs_if_exist:cT - { \g_fontspec_encoding_tl/\l_fontspec_family_tl/##1/\shapedefault } - { - \cs_set_eq:cc - { \g_fontspec_encoding_tl/\l_fontspec_family_tl/##1/\updefault } - { \g_fontspec_encoding_tl/\l_fontspec_family_tl/##1/\shapedefault } - } - } - } -} \DeclareDocumentCommand \setmainhangulfont { O{} m O{} } { \fontspec_set_family:Nnn \luatexkomainhangulfamily { Ligatures=TeX, #1, #3 } { #2 } - \l_luatexko_silent_upshape \cs_set_protected_nopar:Npn \luatexkomainhangulfont { \fontencoding \g_fontspec_encoding_tl @@ -541,7 +596,6 @@ \DeclareDocumentCommand \setsanshangulfont { O{} m O{} } { \fontspec_set_family:Nnn \luatexkosanshangulfamily { Ligatures=TeX, #1, #3 } { #2 } - \l_luatexko_silent_upshape \cs_set_protected_nopar:Npn \luatexkosanshangulfont { \fontencoding \g_fontspec_encoding_tl @@ -558,7 +612,6 @@ \DeclareDocumentCommand \setmonohangulfont { O{} m O{} } { \fontspec_set_family:Nnn \luatexkomonohangulfamily { #1, #3 } { #2 } - \l_luatexko_silent_upshape \cs_set_protected_nopar:Npn \luatexkomonohangulfont { \fontencoding \g_fontspec_encoding_tl @@ -575,7 +628,6 @@ \DeclareDocumentCommand \newhangulfontfamily { m O{} m O{} } { \fontspec_set_family:cnn { luatexko_user_family_ \cs_to_str:N #1 } { #2, #4 } { #3 } - \l_luatexko_silent_upshape \cs_set_protected_nopar:Npn #1 { \cs_set_nopar:Npn \luatexkohangulfont @@ -594,7 +646,6 @@ \DeclareDocumentCommand \hangulfontspec { O{} m O{} } { \fontspec_set_family:Nnn \luatexkohangulfontfamily { #1, #3 } { #2 } - \l_luatexko_silent_upshape \cs_set_nopar:Npn \luatexkohangulfont { \fontencoding \g_fontspec_encoding_tl @@ -606,7 +657,6 @@ \DeclareDocumentCommand \setmainhanjafont { O{} m O{} } { \fontspec_set_family:Nnn \luatexkomainhanjafamily { Ligatures=TeX, #1, #3 } { #2 } - \l_luatexko_silent_upshape \cs_set_protected_nopar:Npn \luatexkomainhanjafont { \fontencoding \g_fontspec_encoding_tl @@ -623,7 +673,6 @@ \DeclareDocumentCommand \setsanshanjafont { O{} m O{} } { \fontspec_set_family:Nnn \luatexkosanshanjafamily { Ligatures=TeX, #1, #3 } { #2 } - \l_luatexko_silent_upshape \cs_set_protected_nopar:Npn \luatexkosanshanjafont { \fontencoding \g_fontspec_encoding_tl @@ -640,7 +689,6 @@ \DeclareDocumentCommand \setmonohanjafont { O{} m O{} } { \fontspec_set_family:Nnn \luatexkomonohanjafamily { #1, #3 } { #2 } - \l_luatexko_silent_upshape \cs_set_protected_nopar:Npn \luatexkomonohanjafont { \fontencoding \g_fontspec_encoding_tl @@ -657,7 +705,6 @@ \DeclareDocumentCommand \newhanjafontfamily { m O{} m O{} } { \fontspec_set_family:cnn { luatexko_user_family_ \cs_to_str:N #1 } { #2, #4 } { #3 } - \l_luatexko_silent_upshape \cs_set_protected_nopar:Npn #1 { \cs_set_nopar:Npn \luatexkohanjafont @@ -676,7 +723,6 @@ \DeclareDocumentCommand \hanjafontspec { O{} m O{} } { \fontspec_set_family:Nnn \luatexkohanjafontfamily { #1, #3 } { #2 } - \l_luatexko_silent_upshape \cs_set_nopar:Npn \luatexkohanjafont { \fontencoding \g_fontspec_encoding_tl @@ -689,7 +735,6 @@ \DeclareDocumentCommand \setmainfallbackfont { O{} m O{} } { \fontspec_set_family:Nnn \luatexkomainfallbackfamily { Ligatures=TeX, #1, #3 } { #2 } - \l_luatexko_silent_upshape \cs_set_protected_nopar:Npn \luatexkomainfallbackfont { \fontencoding \g_fontspec_encoding_tl @@ -706,7 +751,6 @@ \DeclareDocumentCommand \setsansfallbackfont { O{} m O{} } { \fontspec_set_family:Nnn \luatexkosansfallbackfamily { Ligatures=TeX, #1, #3 } { #2 } - \l_luatexko_silent_upshape \cs_set_protected_nopar:Npn \luatexkosansfallbackfont { \fontencoding \g_fontspec_encoding_tl @@ -723,7 +767,6 @@ \DeclareDocumentCommand \setmonofallbackfont { O{} m O{} } { \fontspec_set_family:Nnn \luatexkomonofallbackfamily { #1, #3 } { #2 } - \l_luatexko_silent_upshape \cs_set_protected_nopar:Npn \luatexkomonofallbackfont { \fontencoding \g_fontspec_encoding_tl @@ -740,7 +783,6 @@ \DeclareDocumentCommand \newfallbackfontfamily { m O{} m O{} } { \fontspec_set_family:cnn { luatexko_user_family_ \cs_to_str:N #1 } { #2, #4 } { #3 } - \l_luatexko_silent_upshape \cs_set_protected_nopar:Npn #1 { \cs_set_nopar:Npn \luatexkofallbackfont @@ -759,7 +801,6 @@ \DeclareDocumentCommand \fallbackfontspec { O{} m O{} } { \fontspec_set_family:Nnn \luatexkofallbackfontfamily { #1, #3 } { #2 } - \l_luatexko_silent_upshape \cs_set_nopar:Npn \luatexkofallbackfont { \fontencoding \g_fontspec_encoding_tl @@ -771,9 +812,8 @@ \DeclareDocumentCommand \setmathhangulfont { O{} m O{} } { \fontspec_set_family:Nnn \luatexkomathhangulfamily { #1, #3 } { #2 } - \l_luatexko_silent_upshape \DeclareSymbolFont { mathhangul } - \g_fontspec_encoding_tl \luatexkomathhangulfamily \mddefault \updefault + \g_fontspec_encoding_tl \luatexkomathhangulfamily \seriesdefault \shapedefault \int_compare:nNnF { \Umathcharfam"AC00 } = { \symmathhangul } { \setmathhangulblock{AC00}{D7A3} @@ -785,22 +825,11 @@ \let\adhochanjafont\hanjafontspec \let\adhocfallbackfont\fallbackfontspec % interhangul, interlatincjk, charraise -\def\luatexkosilentupshape{% - \@tfor \@tempa := \mddefault \bfdefault \do {% - \ifcsname \f@encoding/\f@family/\@tempa/\updefault\endcsname \else - \ifcsname \f@encoding/\f@family/\@tempa/\shapedefault\endcsname - \global \expandafter\let - \csname \f@encoding/\f@family/\@tempa/\updefault \expandafter\endcsname - \csname \f@encoding/\f@family/\@tempa/\shapedefault\endcsname - \fi\fi - }% -} \protected\def\addhangulfontfeature#1{% \begingroup \ifdefined\luatexkohangulfont - \fontseries\mddefault\fontshape\shapedefault \luatexkohangulfont \fi + \fontseries\seriesdefault\fontshape\shapedefault \luatexkohangulfont \fi \addfontfeature{#1}% - \luatexkosilentupshape \edef\x{\endgroup \def\noexpand\luatexkohangulfont{% \noexpand\fontencoding{\UTFencname}% @@ -811,9 +840,8 @@ \protected\def\addhanjafontfeature#1{% \begingroup \ifdefined\luatexkohanjafont - \fontseries\mddefault\fontshape\shapedefault \luatexkohanjafont \fi + \fontseries\seriesdefault\fontshape\shapedefault \luatexkohanjafont \fi \addfontfeature{#1}% - \luatexkosilentupshape \edef\x{\endgroup \def\noexpand\luatexkohanjafont{% \noexpand\fontencoding{\UTFencname}% @@ -824,9 +852,8 @@ \protected\def\addfallbackfontfeature#1{% \begingroup \ifdefined\luatexkofallbackfont - \fontseries\mddefault\fontshape\shapedefault \luatexkofallbackfont \fi + \fontseries\seriesdefault\fontshape\shapedefault \luatexkofallbackfont \fi \addfontfeature{#1}% - \luatexkosilentupshape \edef\x{\endgroup \def\noexpand\luatexkofallbackfont{% \noexpand\fontencoding{\UTFencname}% @@ -854,25 +881,22 @@ \AtBeginDocument{ % default hangul fonts \ifdefined\luatexkomainhangulfont\else - \begingroup\rmfamily - \directlua{ luatexko.currenthashangulchars(255) }\expandafter\endgroup - \ifnum\count@=\z@ + \begingroup\rmfamily\expandafter\endgroup + \iffontchar\font"AC00 \else \IfFontExistsTF{UnBatang.ttf} {\setmainhangulfont{UnBatang}[Script=Hangul,Language=Korean]} {} \fi \fi \ifdefined\luatexkosanshangulfont\else - \begingroup\sffamily - \directlua{ luatexko.currenthashangulchars(255) }\expandafter\endgroup - \ifnum\count@=\z@ + \begingroup\sffamily\expandafter\endgroup + \iffontchar\font"AC00 \else \IfFontExistsTF{UnDotum.ttf}{\setsanshangulfont{UnDotum}}{} \fi \fi \ifdefined\luatexkomonohangulfont\else - \begingroup\ttfamily - \directlua{ luatexko.currenthashangulchars(255) }\expandafter\endgroup - \ifnum\count@=\z@ + \begingroup\ttfamily\expandafter\endgroup + \iffontchar\font"AC00 \else \def\@tempa{lmtt}\def\@tempb{LatinModernMono(0)} \ifnum 0\ifx\ttdefault\@tempa 1\else\ifx\ttdefault\@tempb 1\fi\fi >\z@ \IfFontExistsTF{UnDotum.ttf} |