X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=src%2Fpatches%2Flltjp-listings.sty;h=b2c7d9afea2e88c50e01817f5a7b8a8e4d6578ea;hb=67291f7f1dee7f7ace5c41e9b881eb3ca8b727c3;hp=62e2385c984b974af97be572f9d568f9b6ae4d5c;hpb=c3c5bb02c74ec7b6ee0444ea44da7f31d5106df2;p=luatex-ja%2Fluatexja.git diff --git a/src/patches/lltjp-listings.sty b/src/patches/lltjp-listings.sty index 62e2385..b2c7d9a 100644 --- a/src/patches/lltjp-listings.sty +++ b/src/patches/lltjp-listings.sty @@ -1,143 +1,295 @@ % % lltjp-listings.sty % -% Modified from jlisting.sty (by Thor) for LuaTeX-ja. -% \NeedsTeXFormat{LaTeX2e} -\def\filedate{2006/02/20} -\def\fileversion{0.2} -\ProvidesPackage{lltjp-listings}[\filedate\space\fileversion\space(Thor)] -\RequirePackage{listings} -\newcount\lst@nextchar -\let\lst@@ProcessSpace\lst@ProcessSpace -\def\lst@ProcessSpace#1{% - \lst@check@chartype{#1}% - \lst@@ProcessSpace - \lst@whitespacetrue} -\let\lst@@ProcessLetter\lst@ProcessLetter -\def\lst@ProcessLetter#1#2{% - \lst@check@chartype{#2}% - {\lst@@ProcessLetter{#1}}% - \relax} -\let\lst@@ProcessDigit\lst@ProcessDigit -\def\lst@ProcessDigit#1#2{% - \lst@check@chartype{#2}% - {\lst@@ProcessDigit{#1}}% - \relax} -\let\lst@@ProcessOther\lst@ProcessOther -\def\lst@ProcessOther#1#2{% - \lst@check@chartype{#2}% - {\lst@@ProcessOther{#1}}% - \relax} -\let\lst@@ProcessTabulator\lst@ProcessTabulator -\def\lst@ProcessTabulator#1{% - \lst@check@chartype{#1}% - \lst@@ProcessTabulator - \relax} -\def\lst@check@chartype#1#2#3{% - \edef\@tempa{\lst@nextchar=`\string#1\relax}% - \afterassignment\remove@to@nnil - \@tempa\@nnil - #2% - \ifnum\lst@nextchar<\@cclvi - #3% - \else - \lst@ifletter \else \lst@OutputOther \fi - \lst@whitespacefalse - \expandafter\lst@AppendJchar - \fi - #1} -\def\lst@AppendJchar#1#2{% - \lst@check@chartype{#2}% - {\advance\lst@length\@ne\lst@Append{#1}}% - \relax} -\def\lst@check@chartype@BOL#1{% - \edef\@tempa{\lst@nextchar=`\string#1\relax}% - \afterassignment\remove@to@nnil - \@tempa\@nnil - \ifnum\lst@nextchar<\@cclvi\else - \lst@whitespacefalse - \expandafter\lst@AppendJchar - \fi - #1} -\def\lst@InputListing#1{% - \begingroup - \lsthk@PreSet \gdef\lst@intname{#1}% - \expandafter\lstset\expandafter{\lst@set}% - \lsthk@DisplayStyle - \catcode\active=\active - \lst@Init\relax \let\lst@gobble\z@ - \lst@SkipToFirst - \lst@ifprint \def\lst@next{\lst@get@filecontents{#1}}% - \else \let\lst@next\@empty - \fi - \catcode"FFFFF=12%" - \lst@next - \lst@DeInit - \endgroup} -\newread\lst@inputfile -\def\lst@get@filecontents#1{% - \let\lst@filecontents\@empty - \openin\lst@inputfile=#1\relax - \let\@lst@get@filecontents@prevline\relax - \lst@get@filecontents@loop - \closein\lst@inputfile - \lst@filecontents\empty} -\def\lst@get@filecontents@loop{% - \read\lst@inputfile to\@lst@get@filecontents@currline - \ifx\@lst@get@filecontents@prevline\relax\else - \expandafter\expandafter\expandafter\def - \expandafter\expandafter\expandafter\lst@filecontents - \expandafter\expandafter\expandafter{% - \expandafter\lst@filecontents\@lst@get@filecontents@prevline}% - \fi - \let\@lst@get@filecontents@prevline\@lst@get@filecontents@currline - \ifeof\lst@inputfile\else - \expandafter\lst@get@filecontents@loop - \fi} -%%% [この処理も,相当強引です.] -\def\lst@BOLGobble{% - \ifnum\lst@gobble>\z@ - \@tempcnta\lst@gobble\relax - \expandafter\lst@BOLGobble@ - \else - \expandafter\lst@check@chartype@BOL - \fi} -\def\lst@BOLGobble@#1{% - \let\lst@next#1% - \ifx \lst@next\relax\else - \ifx \lst@next\lst@MProcessListing\else - \ifx \lst@next\lst@ProcessFormFeed\else - \ifx \lst@next\lstenv@backslash - \let\lst@next\lstenv@BOLGobble@@ - \else - \let\lst@next\lst@BOLGobble@@ - \ifx #1\lst@ProcessTabulator - \advance\@tempcnta-\lst@tabsize\relax - \ifnum\@tempcnta<\z@ - \lst@length-\@tempcnta \lst@PreGotoTabStop - \fi +\ProvidesPackage{lltjp-listings}[2014/01/09 Patch to listings for LuaTeX-ja] +\RequirePackage{listings,luatexbase-cctb} + +%%%%%%%%%%%%%%%% Japanese support +%% IVS support +\newif\if@ltj@lst@vsraw \@ltj@lst@vsrawfalse +\def\ltj@lst@vscmd{} +\lst@Key{vsraw}f[t]{\lstKV@SetIf{#1}\if@ltj@lst@vsraw} +\lst@Key{vscmd}\relax{\def\ltj@lst@vscmd{#1}} + +% 既定の IVS 出力コマンド +\def\ltjlistingsvsstdcmd#1{\@tempdima=\f@size pt% + \smash{\raisebox{.35\@tempdima}{\tt% + \fboxsep=.1\@tempdima\fbox{\fontsize{.5\@tempdima}{\z@}\selectfont + \oalign{\hss VS\hss\crcr\hss#1\hss\crcr}}}}} +\def\ltj@lst@vscmd{\ltjlistingsvsstdcmd} + +% override \lst@FillFixed@ +% \ltj@hst@hss is \ltj@lst@hss@ivs or \ltj@lst@hss@normal, +% according to vsraw = true or not. +\def\lst@FillFixed@#1{% + \ifx\@empty#1\else\ltj@lst@hss#1\expandafter\lst@FillFixed@\fi} + +\directlua{ + local cat_str = luatexbase.catcodetables['string'] + local cat_lp = luatexbase.catcodetables['latex-package'] + local ubyte = unicode.utf8.byte + luatexja.lst = {} + function luatexja.lst.althss(t) + t = ubyte(t) + if not (t>=0xE0100 and t<0xE01F0) then + tex.sprint(cat_lp, string.char(0x5C) .. 'lst@hss') + end + end +} +\gdef\ltj@lst@hss@ivs#1{% + \directlua{luatexja.lst.althss('\luatexluaescapestring{#1}')}#1% +} + +% lowest level +\newif\if@ltj@lst@kanji +\lst@AddToHook{InitVars}{\@ltj@lst@kanjifalse} + +\def\lst@AppendLetter{% + \ltj@lst@setletterflag\lst@Append} +\def\lst@AppendOther{% + \lst@ifletter\lst@Output\lst@letterfalse\fi\@ltj@lst@kanjifalse + \futurelet\lst@lastother\lst@Append} + +\def\ltj@lst@setletterflag{% + \lst@ifletter + \if@ltj@lst@kanji\lst@Output\@ltj@lst@kanjifalse\fi + \else + \lst@lettertrue\if@ltj@lst@kanji\@ltj@lst@kanjifalse\else\lst@OutputOther\fi + \fi} + +\def\ltj@lst@setkanjiflag{% + \lst@ifletter + \lst@Output + \else + \if@ltj@lst@kanji\else\lst@OutputOther\fi\lst@lettertrue + \fi} + +\def\ltj@lst@setopenflag{% + \lst@ifletter + \lst@letterfalse\lst@Output + \else + \if@ltj@lst@kanji\else\lst@OutputOther\fi + \fi\@ltj@lst@kanjitrue} + +\def\ltj@lst@setcloseflag{% + \lst@ifletter\else\lst@lettertrue\fi\@ltj@lst@kanjitrue} + +% Processing Japanese characters +\def\ltj@lst@ProcessJALetter#1{% + \lst@whitespacefalse + \ifnum\ltjgetparameter{jacharrange}{\ltjgetparameter{chartorange}{`#1}}=0 + \ifnum\ltjgetparameter{postbreakpenalty}{`#1}>0 + \ltj@lst@setopenflag % 開き括弧類 + \else + \ifnum\ltjgetparameter{prebreakpenalty}{`#1}>0 + \ltj@lst@setcloseflag % 閉じ括弧類,句読点 \else - \edef\@tempa{\lst@nextchar=`\string#1\relax}% - \@tempa - \ifnum\lst@nextchar<\@cclvi\else - \advance\@tempcnta\m@ne - \fi - \advance\@tempcnta\m@ne - \fi - \fi \fi \fi \fi - \lst@next} -\def\lst@BOLGobble@@{% - \ifnum\@tempcnta>\z@ - \expandafter\lst@BOLGobble@ - \else - \expandafter\lst@check@chartype@BOL - \fi + \ltj@lst@setkanjiflag % 通常の和文文字 + \fi\fi + \advance\lst@length\@ne % 和文文字は通常の2倍の幅 + \else + \ltj@lst@setletterflag + \fi + \lst@Append#1} + +% 半角カナ処理命令 +\def\ltj@lst@ProcessJALetterHalf#1{% + \lst@whitespacefalse + \ifnum\ltjgetparameter{jacharrange}{\ltjgetparameter{chartorange}{`#1}}=0 + \ifnum\ltjgetparameter{postbreakpenalty}{`#1}>0 + \ltj@lst@setopenflag % 開き括弧類 + \else + \ifnum\ltjgetparameter{prebreakpenalty}{`#1}>0 + \ltj@lst@setcloseflag % 閉じ括弧類 + \else + \ltj@lst@setkanjiflag % 通常の和文文字 + \fi\fi + % 半角カナは欧文文字と同じ幅 + \else + \ltj@lst@setletterflag + \fi + \lst@Append#1} + +% 漢字用異体字セレクタ命令 +\def\ltj@lst@ProcessIVS#1{% + \lst@whitespacefalse + \if@ltj@lst@vsraw + \lst@Append#1\advance\lst@length\m@ne + \else + \lst@TrackNewLines\lst@OutputLostSpace \lst@PrintToken + \setbox\@tempboxa\hbox to 2\lst@width{\hss + \expandafter\expandafter\expandafter\ltj@lst@vscmd + \expandafter{\the\numexpr`#1-"E00EF\relax}%" + \hss}% + \lst@CalcLostSpaceAndOutput\lst@whitespacefalse + \fi } -% -% \begin{修正事項}{1.3} +% Variation Selector +\def\ltj@lst@ProcessVS#1{% + \lst@whitespacefalse + \if@ltj@lst@vsraw + \lst@Append#1\advance\lst@length\m@ne + \else + \lst@TrackNewLines\lst@OutputLostSpace \lst@PrintToken + \setbox\@tempboxa\hbox to 2\lst@width{\hss + \expandafter\expandafter\expandafter\ltj@lst@vscmd + \expandafter{\the\numexpr`#1-"FDFF\relax}%" + \hss}% + \lst@CalcLostSpaceAndOutput\lst@whitespacefalse + \fi +} + + +% 半角カナ,異体字セレクタはアクティブ化 +\def\ltj@@listing@jpsetN#1#2#3{% for (not large) range + \@tempcnta=\numexpr#1-1\relax\@tempcntb=\numexpr 1+#2\relax + \loop \global\advance\@tempcnta\@ne\ifnum\@tempcnta<\@tempcntb\relax + \ltj@@listing@jpsetN@{\@tempcnta}{#3}\repeat +} + +\def\ltj@@listing@jpsetN@#1#2{{% + \@tempcnta=#1 \lccode`\~=\@tempcnta \lccode`\/=\@tempcnta + \lowercase{\gdef\@temp{\gdef~{#2/}}}}% + \@temptokena\expandafter\expandafter\expandafter\expandafter% + \expandafter\expandafter\expandafter{\expandafter\expandafter% + \expandafter\the\expandafter\@temptokena\@temp}% +} +\@temptokena{} +\ltj@@listing@jpsetN{65377}{65439}{\ltj@lst@ProcessJALetterHalf} +\ltj@@listing@jpsetN{65024}{65039}{\ltj@lst@ProcessVS} +\ltj@@listing@jpsetN{917760}{917999}{\ltj@lst@ProcessIVS} +\xdef\ltj@@listing@jpcmd{\the\@temptokena}\@temptokena{} + +% catcode 対策 +\newluatexcatcodetable\CatcodeTableLTJlistings +\setluatexcatcodetable\CatcodeTableLTJlistings{% + \luatexcatcodetable\CatcodeTableLaTeXAtLetter + \catcode"FFFFF=13%" + \SetCatcodeRange{"FF61}{"FF9F}{13}% 半角カナ + \SetCatcodeRange{"E0100}{"E01EF}{13}% 漢字用異体字セレクタ + \SetCatcodeRange{"FE00}{"FE0F}{13}% Variation Selector +} + +% We redefine \lst@BeginDropInput, since now we have +% two additional `process macros'. +\def\lst@BeginDropInput#1{% + \lst@EnterMode{#1}% + {\lst@modetrue + \let\lst@OutputBox\@gobble + \let\lst@ifdropinput\iftrue + \let\lst@ProcessLetter\@gobble + \let\lst@ProcessDigit\@gobble + \let\lst@ProcessOther\@gobble + \let\lst@ProcessSpace\@empty + \let\lst@ProcessTabulator\@empty + \let\lst@ProcessFormFeed\@empty + \let\ltj@lst@ProcessJALetter\@gobble % added + \let\ltj@lst@ProcessJALetterHalf\@gobble % added +}} + + +% hook! +\lst@AddToHook{Init}{ + \luatexcatcodetable\CatcodeTableLTJlistings\ltj@@listing@jpcmd + \lccode`\~="FFFFF\lowercase{\def~{\ltj@lst@ProcessJALetter}}%" + \directlua{luatexbase.add_to_callback('process_input_buffer', + function(buf) + local ret = '' + for i = 1, utf.len(buf) do + local c = utf.sub(buf, i, i) + local cu = utf.byte(c) + if cu > 0x80 and tex.getcatcode(cu) \string~= 13 then + ret = ret .. utf.char(1048575) % U+FFFFF + end + ret = ret .. c + end + return ret + end, 'ltj.listings_unicode', 1)}% + \if@ltj@lst@vsraw + \let\ltj@lst@hss=\ltj@lst@hss@ivs + \else + \let\ltj@lst@hss=\lst@hss + \fi +} +\lst@AddToHook{ExitVars}{% + \directlua{luatexbase.remove_from_callback('process_input_buffer', + 'ltj.listings_unicode')}% +} + + +% 白線対策 +\def\lst@OutputToken{% + \lst@TrackNewLines \lst@OutputLostSpace + \lst@ifgobbledws + \lst@gobbledwhitespacefalse + \lst@@discretionary + \fi + \lst@CheckMerge + {\lst@thestyle{\lst@FontAdjust + \setbox\@tempboxa\lst@hbox + {\lsthk@OutputBox + \lst@lefthss + \expandafter\lst@FillOutputBox\the\lst@token\@empty + \lst@righthss}% + \ht\@tempboxa=0pt\dp\@tempboxa=0pt + \lst@CalcLostSpaceAndOutput}}% + \lst@ResetToken} + +%%%%%%%%%%%%%%%% escape to \LaTeX +\lstloadaspects{escape} +\gdef\lst@Escape#1#2#3#4{% + \lst@CArgX #1\relax\lst@CDefX + {}% + {\lst@ifdropinput\else + \lst@TrackNewLines\lst@OutputLostSpace \lst@XPrintToken + \lst@InterruptModes + \lst@EnterMode{\lst@TeXmode}{\lst@modetrue}% + \ifx\^^M#2% + \lst@CArg #2\relax\lst@ActiveCDefX + {}% + {\lst@escapeend #4\lst@LeaveAllModes\lst@ReenterModes}% + {\lst@MProcessListing}% + \else + \lst@CArg #2\relax\lst@ActiveCDefX + {}% + {\lst@escapeend #4\lst@LeaveAllModes\lst@ReenterModes + \lst@newlines\z@ \lst@whitespacefalse}% + {}% + \fi + #3\catcode"FFFFF=9\lst@escapebegin%" + \fi}% + {}} + +%%%%%%%%%%%%%%%% +\lstloadaspects{writefile} +\begingroup \catcode`\^^I=11 +\gdef\lst@WFBegin#1#2{% + \begingroup + \let\lst@OutputBox#1% + \def\lst@Append##1{% + \advance\lst@length\@ne + \expandafter\lst@token\expandafter{\the\lst@token##1}% + \ifx ##1\lst@outputspace \else + \lst@WFAppend##1% + \fi}% + \lst@lAddTo\lst@PreGotoTabStop{\lst@WFAppend{^^I}}% + \lst@lAddTo\lst@ProcessSpace{\lst@WFAppend{ }}% + \def\ltj@lst@ProcessIVS##1{\lst@whitespacefalse\lst@Append##1}% + \def\ltj@lst@ProcessVS##1{\lst@whitespacefalse\lst@Append##1}% + \let\lst@DeInit\lst@WFDeInit + \let\lst@MProcessListing\lst@WFMProcessListing + \lst@WFifopen\else + \immediate\openout\lst@WF=#2\relax + \global\let\lst@WFifopen\iftrue + \@gobbletwo\fi\fi + \fi} +\endgroup + + +% \begin{修正事項}{1.3} from jlisting.sty % ちょっとした修正 \gdef\lst@breakProcessOther#1{\lst@ProcessOther#1} % ソースコード目次における文字と番号の空き @@ -146,20 +298,4 @@ \def\lstlistingname{ソースコード} \def\lstlistlistingname{ソースコード目次} % \end{修正事項} - - -% Changes for LuaTeX-ja: -% 1. \char"FFFFF は通常行末用コメント文字として使われる. -% だが,それはソースコードの組版には邪魔ものとなる. -%\lst@AddToHook{Init}{\catcode"FFFFF=9 } -%\lst@AddToHook{DeInit}{\catcode"FFFFF=14 } -%\lst@Def{1048575}{} - -% 2. listing な環境の処理中に \DeclareFontShape の (s)sub が実行されると,なぜか -% ! Use of set@size@funct@args@ doesn't match its definition. -% のエラーが出る. -% \ifnot@nil #1-> \def\reserved@a{#1}... の \reserved@a=\set@size@funct@args@ -% がなぜか実行される? -% ad hoc な対策として事前に必要な (s)sub は実行しておくことにする. -\lst@AddToHook{Init}{\begingroup\itshape\bfseries\upshape\endgroup} -\endinput +\endinput \ No newline at end of file