OSDN Git Service

listings 用に kmaeda さんのアイデアを採用.
[luatex-ja/luatexja.git] / test / test13-listings.tex
1 %#!lualatex
2 \documentclass{article}
3
4 \usepackage{luatexja-fontspec}
5 \usepackage{listings,color,showexpl}
6 \usepackage
7 [
8         papersize={100mm,100mm},
9         hmargin={5mm,5mm},
10         vmargin={5mm,5mm}
11 ]{geometry}
12 \pagestyle{empty}
13
14 \lstset
15 {
16         language=sh, extendedchars=false,
17         backgroundcolor=\color[gray]{.75},
18         breaklines=true,
19     basewidth={0.55\zw, 0.45em},
20         numbers=left,numberstyle=\tiny, numbersep=2pt,
21 }
22
23 \lstnewenvironment{env}[1]
24 {
25         \ifx\relax#1\else
26         \renewcommand{\lstlistingname}{ex}
27         \lstset
28         {
29                 caption=#1,
30         }
31         \fi
32 }{}
33 \DeclareFontShape{JY3}{mc}{m}{sl}{<-> s * [0.92489] psft:Ryumin-Light:jfm=ujis;slant=0.167}{}
34 \DeclareFontShape{JY3}{mc}{m}{it}{<-> ssub* mc/m/sl}{}
35
36 \setmainfont{TeX Gyre Pagella}
37 \setmonofont{TeX Gyre Cursor}
38 \begin{document}
39 This test file is based on a.tex\footnote{This can be downloaded from {\tt https://gist.github.com/1574793}.} by x19290.
40
41
42 \textbf{SOLVED}: bad folding and not slanted problems are common in pLaTeX and LuaTeX-ja.
43
44 The cause of the latter problem is that Japanese fonts don't have italic shape by default.
45 In this document, we define them by
46 \begin{lstlisting}[language={[AlLaTeX]TeX}, basicstyle=\ttfamily]
47 \DeclareFontShape{JY3}{mc}{m}{sl}{<-> s * [0.92489] psft:Ryumin-Light:jfm=ujis;slant=0.167}{}
48 \DeclareFontShape{JY3}{mc}{m}{it}{<-> ssub* mc/m/sl}{}
49 \end{lstlisting}
50 \newpage
51
52 We also avoid white band problem, by setting both the height and the depth of each 
53 letter/word to 0\,pt. 
54
55 \begin{env}{\relax}
56 #!/bin/sh
57 #長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い
58 長い長い長い長い長い長い長い長い長い長い長い長い,長い長い長い長い長い長い
59 #I.長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い長いI
60 長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い
61 #IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII
62 IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII IIII
63 \end{env}
64
65 Note that any \emph{kinsoku shori} is not performed inside \textsf{lstlisting} environment,
66 as the line~3 in output above. We leave it to further development.
67 \newpage
68
69 \textbf{SOLVED}: LuaTeX-ja specific problem:
70 when the \emph{begin} line of a listings environment ends with JAchar,
71 the first line of the listing is not rendered.
72
73 \begin{env}{problem; shebang not rendered --- 問題}
74 #!/bin/bash
75 :
76 \end{env}
77
78 \begin{LTXexample}[language=TeX]
79 え!1あ,い・あ)う(え
80 え!2あ
81 \end{LTXexample}
82
83 \lstinputlisting{test13-listings.tmp}
84
85 \begin{lstlisting}
86 え!1あアイウエオ
87 え!2あ
88 \end{lstlisting}
89 \newpage
90 \textbf{Ticket \#29311}
91
92 \begin{env}{\relax}
93 長い長い長い長い長い長い長い長い長い長い長い長い#い長い
94 長い長い長い長い長い長い長い長い長い長い長い長aaaa#::い長い
95 長い長い長い長い長い長い長い長い長い長い長い長い,長い長い
96 長い長い長い長い長い長い長い長い長い長い長い長aa,::い長い
97 長い長い長い長い長い長い長い長い長い長い長い長,,::い長い
98 長い長い長い長い長い長い長い長い長い長い長い長(い長い
99 長い長い長い長い長い長い長い長い長い長い長いaa(い長い
100 長い長い長い長い長い長い長い長い長い長い長い長(aa長い
101 長い長い長い長い長い長い長い長い長い長い長い長い)(長い
102 \end{env}
103
104 \newpage
105 \textbf{Ticket \#29604}
106
107 \setmonofont{DejaVu Sans Mono}
108 \ltjsetparameter{jacharrange={-2,-3,-8}}
109 ギリシャ文字欧文扱い
110
111 \begin{lstlisting}[basewidth=.5em,basicstyle=\tt, emph={TeX}, emphstyle=\color{red}]
112 01234567890123456789
113 !あ!漢!α!×!
114 \TeX はギリシャ文字のΤ-Ε-Χ(タウ・イプシロン・カイ)であるから、……
115 \TeX is an abbreviation of τέχνη (ΤΕΧΝΗ – technē).
116 \end{lstlisting}
117
118 \ltjsetparameter{jacharrange={+2,+8,+3}}
119 ギリシャ文字和文扱い
120
121 \begin{lstlisting}[basewidth=.5em,basicstyle=\tt, emph={TeX}, emphstyle=\color{red}]
122 01234567890123456789
123 !あ!漢!α!×!
124 \TeX はギリシャ文字のΤ-Ε-Χ(タウ・イプシロン・カイ)であるから、……
125 \TeX is an abbreviation of τέχνη (ΤΕΧΝΗ – technē).
126 \end{lstlisting}
127 \end{document}