OSDN Git Service

Merge branch 'kitagawa_test' of git.sourceforge.jp:/gitroot/luatex-ja/luatexja into...
[luatex-ja/luatexja.git] / test / test13-listings.tex
1 %#!lualatex
2 \documentclass{article}
3
4 \usepackage{listings,color,showexpl,comment}
5 \lstMakeShortInline÷
6 \usepackage{luatexja-fontspec,amsmath}
7 \usepackage{luatexja-otf}\directlua{luatexja.otf.enable_ivs()}
8 \usepackage
9 [
10         papersize={100mm,100mm},
11         hmargin={5mm,5mm},
12         vmargin={5mm,5mm}
13 ]{geometry}
14 \pagestyle{empty}
15
16 \lstset
17 {
18         language=sh, extendedchars=false,
19         backgroundcolor=\color[gray]{.75},
20         breaklines=true,
21         explpreset={columns=fixed},
22     basewidth={0.5\zw, 0.45em},
23         numbers=left,numberstyle=\tiny, numbersep=2pt,
24 }
25
26 \lstnewenvironment{env}[1]
27 {
28         \ifx\relax#1\else
29         \renewcommand{\lstlistingname}{ex}
30         \lstset
31         {
32                 caption=#1,
33         }
34         \fi
35 }{}
36 \DeclareKanjiFamily{JY3}{koz}{}
37 \DeclareFontShape{JY3}{koz}{m}{n}{<-> s * [1.2] KozMinPr6N-Regular:jfm=ujis}{}
38 \DeclareFontShape{JY3}{koz}{m}{sl}{<-> s * [1.2] psft:Ryumin-Light:jfm=ujis;slant=0.167}{}
39 \DeclareFontShape{JY3}{koz}{m}{it}{<-> ssub* koz/m/sl}{}
40 \def\mcdefault{koz}
41
42 \setmainfont{TeX Gyre Pagella}
43 \setmonofont{TeX Gyre Cursor}
44 \def\cs#1{\hbox{\texttt{\textbackslash #1}}}
45 \begin{document}
46
47 This test file is based on a.tex\footnote{This can be downloaded from {\tt https://gist.github.com/1574793}.} by x19290.
48
49
50 \textbf{SOLVED}: bad folding and not slanted problems are common in pLaTeX and LuaTeX-ja.
51
52 The cause of the latter problem is that Japanese fonts don't have italic shape by default.
53 In this document, we define them by
54 \begin{lstlisting}[language={[AlLaTeX]TeX}, basicstyle=\ttfamily]
55 \DeclareFontShape{JY3}{mc}{m}{sl}{<-> s * [0.92489] psft:Ryumin-Light:jfm=ujis;slant=0.167}{}
56 \DeclareFontShape{JY3}{mc}{m}{it}{<-> ssub* mc/m/sl}{}
57 \end{lstlisting}
58 \newpage
59
60 We also avoid white band problem, by setting the value of \cs{lineskiplimit} to
61 \begin{multline}
62  -\min(\cs{cht}-\cs{ht}\cs{strutbox}, 0)\\
63  -\min(\cs{cdp}-\cs{dp}\cs{strutbox}, 0).
64 \end{multline}
65
66 Note: we still have a white band if the first line is line-broken.
67
68 \begin{env}{\relax}
69 #!/bin/sh
70 #長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い
71 長い長い長い長い長い長い長い長い長い長い長い長い,長い長い長い長い長い長い
72 #長い長い長い長い長い長い長い長い長い長い長い長い,長い長い長い長い長い長い
73 #I.長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い長いI
74 長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い
75 #IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII
76 IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII
77 \end{env}
78
79 \newpage
80
81 \textbf{SOLVED}: LuaTeX-ja specific problem:
82 when the \emph{begin} line of a listings environment ends with JAchar,
83 the first line of the listing is not rendered.
84
85 \begin{env}{problem; shebang not rendered --- 問題}
86 #!/bin/bash
87 :
88 \end{env}
89
90 \begin{LTXexample}[language=TeX]
91 え!1あ,い・あ)う(え
92 え!2あ
93 \end{LTXexample}
94
95 \lstinputlisting{test13-listings.tmp}
96
97 \begin{lstlisting}
98 え!1あアイウエオ
99 え!2あ
100 \end{lstlisting}
101 \newpage
102 \textbf{Ticket \#29311}
103
104 \begin{env}{\relax}
105 長い長い長い長い長い長い長い長い長い長い長い長aaa長い::い長い
106 長い長い長い長い長い長い長い長い長い長い長い長aaaa長い::い長い
107 長い長い長い長い長い長い長い長い長い長い長い長い長い,長い長い
108 あ長い長い長い長い長い長い長い長い長い長い長い長い長い,長い長い
109 長い長い長い長い長い長い長い長い長い長い長い長い長a,::い長い
110 長い長い長い長い長い長い長い長い長い長い長い長い長aa,::い長い
111 長い長い長い長い長い長い長い長い長い長い長い長い長aaa,::い長い
112 長い長い長い長い長い長い長い長い長い長い長い長い長aaaa,::い長い
113 長い長い長い長い長い長い長い長い長い長い長い長い長い,,::い長い
114 長い長い長い長い長い長い長い長い長い長い長い長(い長い
115 長い長い長い長い長い長い長い長い長い長い長いaa(い長い
116 長い長い長い長い長い長い長い長い長い長い長い長(aa長い
117 長い長い長い長い長い長い長い長い長い長い長い長い)(長い
118 あ長い長い長い長い長い長い長い長い長い長い長い長い)(長い
119 \end{env}
120
121 \newpage
122 \textbf{Ticket \#29604}
123
124 \setmonofont{DejaVu Sans Mono}
125 \ltjsetparameter{jacharrange={-2,-3,-8}}
126 ギリシャ文字欧文扱い
127
128 \begin{lstlisting}[basewidth=.5em,basicstyle=\tt, emph={TeX}, emphstyle=\color{red}]
129 01234567890123456789
130 !あ!漢!α!×!
131 \TeX はギリシャ文字のΤ-Ε-Χ(タウ・イプシロン・カイ)であるから、……
132 \TeX is an abbreviation of τέχνη (ΤΕΧΝΗ – technē).
133 \end{lstlisting}
134
135 \ltjsetparameter{jacharrange={+2,+8,+3}}
136 ギリシャ文字和文扱い
137
138 \begin{lstlisting}[basewidth=.5em,basicstyle=\tt, emph={TeX}, emphstyle=\color{red}]
139 01234567890123456789
140 !あ!漢!α!×!
141 \TeX はギリシャ文字のΤ-Ε-Χ(タウ・イプシロン・カイ)であるから、……
142 \TeX is an abbreviation of τέχνη (ΤΕΧΝΗ – technē).
143 \end{lstlisting}
144
145 \newpage
146 IVS対応1: \texttt{vsraw=false} (default)
147
148 \begin{LTXexample}[escapechar=\%, basicstyle=\tt]
149 123456789012345678
150 1葛󠄀城,葛󠄁飾
151 󠄀a
152 \end{LTXexample}
153
154 IVS対応2: \texttt{vsraw=true}
155
156 \begin{LTXexample}[escapechar=\%,vsraw, basicstyle=\tt]
157 123456789012345678
158 1葛󠄀城,葛󠄁飾アイウ
159 \end{LTXexample}
160
161 \newpage
162
163 下の行において,最初の「1」の場所がずれてしまうのは半ば仕方がないとも言える.
164 1行目では,「1234567890」が前後・文字間に計11箇所の等量の空白を入れて10全角の領域に
165 出力されているのに対し,2,~3行目では「1」が全角幅に左右中央で出力されているからである.
166 \begin{lstlisting}[escapechar=\%,vsraw, basewidth=1\zw, basicstyle=\tt]
167 1234567890
168 1あ,23
169 1あ2,3
170 1234567890
171 \end{lstlisting}
172
173 \texttt{doubleletterspace}オプションを指定すると,出力単位中の文字と文字の間隔を2倍にするため,
174 下の例の「1」のように,各文字の垂直位置が揃いやすくなる.
175 \begin{lstlisting}[escapechar=\%,doubleletterspace, basewidth=1\zw, basicstyle=\tt]
176 1234567890
177 1あ,23
178 1あ2,3
179 1)2,3
180 1234567890
181 \end{lstlisting}
182
183
184 \newpage
185 \textbf{Ticket \#34786}
186 \ltjsetparameter{autoxspacing=false}
187
188 foo \lstinline[basicstyle=\tt]!ba{}#shr! baz あ
189
190 1あ\lstinline[basicstyle=\tt]{bar  s}hoge
191
192 2あ\lstinline[basicstyle=\tt]{bar..{a}hoge
193
194 foo \lstinline[basicstyle=\tt\gtfamily]!exit 0; #shbar! baz あ
195
196 foo \lstinline[basicstyle=\tt\gtfamily]!あreturn 0; #shbar! baz あ
197
198 3あ\lstinline[basicstyle=\tt]{fexit #sh$ar}hoge
199
200 4あ\lstinline[basicstyle=\tt]{いbexit #sh$ar}hoge
201
202 \bigskip
203 \textbf{Ticket \#35484}
204
205 \colorbox{red}{\lstinline!aiu#sheoxyz!}
206 \colorbox{red}{\lstinline!あいexit 0;#shうえお!}
207
208
209 \colorbox{red}{\lstinline{aGiu#sheoxyz}}
210 \colorbox{red}{\lstinline{あGいexit 0;#shうえお}}
211
212 あおいうえお
213 \begin{lstlisting}[frame=single]
214 aiu
215 \end{lstlisting}
216 あいうえお
217
218 \bigskip
219 \textbf{Escape character}
220 \begin{lstlisting}[escapechar=\#,basicstyle=\ttfamily]
221 1234567890123457890
222 aiu# \textcolor{red}{e} #o#\textcolor{red}{ka}#ki
223 \end{lstlisting}
224 \typeout{AAAA}
225
226 \bigskip
227 \textbf{Ticket \#44426}\lstset{basicstyle=\itshape}
228 Foo ÷fo#shbarあ{#}o÷ Foo
229 \colorbox{green}{÷fo#shbarあ{#}o÷}
230
231 \lstMakeShortInline あ
232 ÷いfo#shbarあ{#}}o÷
233 あえbazあ
234 あbaxあ
235 \end{document}