review 2.5.0 → 3.0.0.preview1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +28 -10
  3. data/.travis.yml +11 -2
  4. data/NEWS.ja.md +89 -17
  5. data/NEWS.md +92 -0
  6. data/README.md +1 -1
  7. data/Rakefile +0 -13
  8. data/bin/review-catalog-converter +83 -37
  9. data/bin/review-check +17 -5
  10. data/bin/review-compile +1 -1
  11. data/bin/review-index +6 -0
  12. data/bin/review-init +3 -155
  13. data/bin/review-preproc +0 -5
  14. data/bin/review-validate +21 -7
  15. data/bin/review-vol +13 -5
  16. data/doc/config.yml.sample +12 -7
  17. data/doc/config.yml.sample-simple +1 -1
  18. data/doc/format.ja.md +39 -3
  19. data/doc/format.md +39 -3
  20. data/doc/format_idg.ja.md +0 -4
  21. data/doc/pdfmaker.ja.md +1 -1
  22. data/doc/pdfmaker.md +1 -1
  23. data/doc/sample.css +7 -0
  24. data/lib/epubmaker/content.rb +31 -12
  25. data/lib/epubmaker/epubcommon.rb +10 -3
  26. data/lib/epubmaker/epubv2.rb +11 -3
  27. data/lib/epubmaker/epubv3.rb +11 -3
  28. data/lib/epubmaker/producer.rb +55 -20
  29. data/lib/review/book/base.rb +63 -48
  30. data/lib/review/book/chapter.rb +19 -7
  31. data/lib/review/book/compilable.rb +5 -20
  32. data/lib/review/book/image_finder.rb +10 -3
  33. data/lib/review/book/index.rb +30 -9
  34. data/lib/review/book/part.rb +9 -6
  35. data/lib/review/book.rb +0 -14
  36. data/lib/review/builder.rb +110 -18
  37. data/lib/review/catalog.rb +24 -4
  38. data/lib/review/compiler.rb +3 -1
  39. data/lib/review/configure.rb +43 -9
  40. data/lib/review/epubmaker/reviewheaderlistener.rb +57 -0
  41. data/lib/review/epubmaker.rb +129 -85
  42. data/lib/review/htmlbuilder.rb +76 -58
  43. data/lib/review/htmlutils.rb +20 -13
  44. data/lib/review/i18n.rb +6 -2
  45. data/lib/review/idgxmlbuilder.rb +52 -41
  46. data/lib/review/init.rb +194 -0
  47. data/lib/review/latexbuilder.rb +118 -34
  48. data/lib/review/latexutils.rb +5 -5
  49. data/lib/review/logger.rb +2 -1
  50. data/lib/review/makerhelper.rb +1 -1
  51. data/lib/review/markdownbuilder.rb +66 -6
  52. data/lib/review/md2inaobuilder.rb +2 -2
  53. data/lib/review/pdfmaker.rb +74 -22
  54. data/lib/review/plaintextbuilder.rb +8 -4
  55. data/lib/review/preprocessor.rb +14 -17
  56. data/lib/review/sec_counter.rb +8 -2
  57. data/lib/review/textmaker.rb +2 -2
  58. data/lib/review/textutils.rb +9 -2
  59. data/lib/review/tocparser.rb +7 -4
  60. data/lib/review/tocprinter.rb +3 -1
  61. data/lib/review/version.rb +1 -1
  62. data/lib/review/webmaker.rb +19 -7
  63. data/lib/review/webtocprinter.rb +8 -4
  64. data/review.gemspec +4 -3
  65. data/templates/latex/config.erb +84 -0
  66. data/templates/latex/layout.tex.erb +76 -361
  67. data/templates/latex/review-jlreq/README.md +22 -0
  68. data/templates/latex/review-jlreq/review-base.sty +178 -0
  69. data/templates/latex/review-jlreq/review-custom.sty +1 -0
  70. data/templates/latex/review-jlreq/review-jlreq.cls +141 -0
  71. data/templates/latex/review-jlreq/review-style.sty +149 -0
  72. data/templates/latex/review-jlreq/reviewmacro.sty +8 -0
  73. data/templates/latex/review-jsbook/jumoline.sty +310 -0
  74. data/templates/latex/review-jsbook/plistings.sty +326 -0
  75. data/templates/latex/review-jsbook/review-base.sty +405 -0
  76. data/templates/latex/review-jsbook/review-custom.sty +1 -0
  77. data/templates/latex/review-jsbook/review-style.sty +38 -0
  78. data/templates/latex/review-jsbook/reviewmacro.sty +8 -0
  79. data/templates/latex-compat2/layout.tex.erb +387 -0
  80. data/test/assets/test_template.tex +105 -235
  81. data/test/assets/test_template_backmatter.tex +133 -14
  82. data/test/book_test_helper.rb +1 -1
  83. data/test/run_test.rb +2 -0
  84. data/test/sample-book/src/Rakefile +11 -6
  85. data/test/sample-book/src/config.yml +2 -2
  86. data/test/sample-book/src/sty/reviewmacro.sty +1 -39
  87. data/test/sample-book/src/style.css +6 -0
  88. data/test/syntax-book/config.yml +1 -1
  89. data/test/test_book.rb +13 -16
  90. data/test/test_book_chapter.rb +4 -10
  91. data/test/test_book_part.rb +4 -3
  92. data/test/test_catalog.rb +15 -4
  93. data/test/test_helper.rb +2 -2
  94. data/test/test_htmlbuilder.rb +78 -10
  95. data/test/test_htmlutils.rb +12 -5
  96. data/test/test_idgxmlbuilder.rb +1 -1
  97. data/test/test_latexbuilder.rb +94 -49
  98. data/test/test_latexbuilder_v2.rb +1077 -0
  99. data/test/test_logger.rb +20 -0
  100. data/test/test_markdownbuilder.rb +10 -0
  101. data/test/test_pdfmaker.rb +6 -7
  102. data/test/test_plaintextbuilder.rb +1 -1
  103. data/test/test_review_ext.rb +0 -1
  104. data/test/test_rstbuilder.rb +1 -1
  105. data/test/test_topbuilder.rb +19 -7
  106. data/test/test_webtocprinter.rb +14 -14
  107. data/{test/sample-book/src/vendor → vendor}/jumoline/README +0 -0
  108. data/{test/sample-book/src/vendor → vendor}/jumoline/jumoline.dtx +0 -0
  109. data/{test/sample-book/src/vendor → vendor}/jumoline/jumoline.ins +0 -0
  110. data/{test/sample-book/src/vendor → vendor}/jumoline/lppl.txt +0 -0
  111. data/vendor/plistings/.gitignore +9 -0
  112. data/vendor/plistings/LICENSE +21 -0
  113. data/vendor/plistings/README.md +18 -0
  114. data/vendor/plistings/plistings.sty +326 -0
  115. data/vendor/plistings/test1.tex +174 -0
  116. data/vendor/plistings/test2.tex +54 -0
  117. metadata +48 -19
  118. data/lib/review/unfold.rb +0 -129
  119. data/test/CHAPS +0 -2
  120. data/test/bib.re +0 -13
  121. data/test/test.re +0 -43
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+ require 'review/logger'
3
+
4
+ class LoggerTest < Test::Unit::TestCase
5
+ def setup
6
+ end
7
+
8
+ def test_logging
9
+ old_stderr = STDERR.dup
10
+ IO.pipe do |r, w|
11
+ STDERR.reopen(w)
12
+ @logger = ReVIEW::Logger.new
13
+ @logger.warn('test')
14
+ msg = r.readline
15
+ STDERR.reopen(old_stderr)
16
+
17
+ assert_equal "WARN: test\n", msg
18
+ end
19
+ end
20
+ end
@@ -26,6 +26,16 @@ class MARKDOWNBuilderTest < Test::Unit::TestCase
26
26
  assert_equal %Q(\n> foobar\n> \n> buz\n\n), actual
27
27
  end
28
28
 
29
+ def test_memo
30
+ actual = compile_block("//memo[this is @<b>{test}<&>_]{\ntest1\n\ntest@<i>{2}\n//}\n")
31
+ assert_equal %Q(<div class="memo">\n<p class="caption">this is **test**<&>_</p>\ntest1\ntest*2*\n</div>\n), actual
32
+ end
33
+
34
+ def test_noindent
35
+ actual = compile_block("//noindent\nfoo\nbar\n\nfoo2\nbar2\n")
36
+ assert_equal %Q(<p class="noindent">foobar</p>\n\nfoo2bar2\n\n), actual
37
+ end
38
+
29
39
  def test_inline_em
30
40
  assert_equal 'test*foo*abc', compile_inline('test@<em>{foo}abc')
31
41
  end
@@ -10,7 +10,7 @@ class PDFMakerTest < Test::Unit::TestCase
10
10
  @config.merge!(
11
11
  'bookname' => 'sample',
12
12
  'title' => 'Sample Book',
13
- 'version' => 2,
13
+ 'review_version' => 3,
14
14
  'urnid' => 'http://example.jp/',
15
15
  'date' => '2011-01-01',
16
16
  'language' => 'ja',
@@ -141,6 +141,7 @@ class PDFMakerTest < Test::Unit::TestCase
141
141
  def test_template_content
142
142
  Dir.mktmpdir do
143
143
  @maker.basedir = Dir.pwd
144
+ @maker.erb_config
144
145
  tmpl = @maker.template_content
145
146
  expect = File.read(File.join(assets_dir, 'test_template.tex'))
146
147
  assert_equal(expect, tmpl)
@@ -149,9 +150,9 @@ class PDFMakerTest < Test::Unit::TestCase
149
150
 
150
151
  def test_gettemplate_with_backmatter
151
152
  @config.merge!(
152
- 'backcover' => 'backcover.html',
153
- 'profile' => 'profile.html',
154
- 'advfile' => 'advfile.html'
153
+ 'backcover' => 'backcover.tex',
154
+ 'profile' => 'profile.tex',
155
+ 'advfile' => 'advfile.tex'
155
156
  )
156
157
  Dir.mktmpdir do |dir|
157
158
  Dir.chdir(dir) do
@@ -161,12 +162,10 @@ class PDFMakerTest < Test::Unit::TestCase
161
162
  File.open(File.join(dir, 'advfile.tex'), 'w') { |f| f.write(advfile) }
162
163
  backcover = "\\clearpage\n\\thispagestyle{empty}\\AddToShipoutPictureBG{%\n\\AtPageLowerLeft{\\includegraphics[width=\\paperwidth,height=\\paperheight]{images/backcover.png}}\n}\n\\null"
163
164
  File.open(File.join(dir, 'backcover.tex'), 'w') { |f| f.write(backcover) }
164
-
165
165
  expect = File.read(File.join(assets_dir, 'test_template_backmatter.tex'))
166
-
167
166
  @maker.basedir = Dir.pwd
167
+ @maker.erb_config
168
168
  tmpl = @maker.template_content
169
- tmpl.gsub!(/\A.*%% backmatter begins\n/m, '')
170
169
  assert_equal(expect, tmpl)
171
170
  end
172
171
  end
@@ -12,7 +12,7 @@ class PLAINTEXTBuidlerTest < Test::Unit::TestCase
12
12
  @config = ReVIEW::Configure.values
13
13
  @config['secnolevel'] = 2
14
14
  @config['language'] = 'ja'
15
- @book = Book::Base.new(nil)
15
+ @book = Book::Base.new
16
16
  @book.config = @config
17
17
  @compiler = ReVIEW::Compiler.new(@builder)
18
18
  @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
@@ -18,7 +18,6 @@ module ReVIEW
18
18
  end
19
19
  EOB
20
20
 
21
- ReVIEW::Book::Base.clear_rubyenv ## to load review-ext.rb
22
21
  mktmpbookdir('CHAPS' => "ch01.re\n",
23
22
  'ch01.re' => "= test\n\ntest.\n",
24
23
  'review-ext.rb' => review_ext) do |_dir, _book, _files|
@@ -12,7 +12,7 @@ class RSTBuidlerTest < Test::Unit::TestCase
12
12
  @config = ReVIEW::Configure.values
13
13
  @config['secnolevel'] = 2
14
14
  @config['language'] = 'ja'
15
- @book = Book::Base.new(nil)
15
+ @book = Book::Base.new
16
16
  @book.config = @config
17
17
  @compiler = ReVIEW::Compiler.new(@builder)
18
18
  @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
@@ -12,19 +12,13 @@ class TOPBuidlerTest < Test::Unit::TestCase
12
12
  @config = ReVIEW::Configure.values
13
13
  @config['secnolevel'] = 2
14
14
  @config['language'] = 'ja'
15
- @book = Book::Base.new(nil)
15
+ @book = Book::Base.new
16
16
  @book.config = @config
17
17
  @compiler = ReVIEW::Compiler.new(@builder)
18
18
  @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
19
19
  location = Location.new(nil, nil)
20
20
  @builder.bind(@compiler, @chapter, location)
21
21
 
22
- @builder.instance_eval do
23
- # to ignore lineno in original method
24
- def warn(msg)
25
- puts msg
26
- end
27
- end
28
22
  I18n.setup(@config['language'])
29
23
  end
30
24
 
@@ -297,6 +291,24 @@ class TOPBuidlerTest < Test::Unit::TestCase
297
291
  assert_equal %Q(◆→開始:TeX式←◆\n\\sin\n1^{2}\n◆→終了:TeX式←◆\n\n), actual
298
292
  end
299
293
 
294
+ def test_inline_w
295
+ Dir.mktmpdir do |dir|
296
+ File.open(File.join(dir, 'words.csv'), 'w') do |f|
297
+ f.write <<EOB
298
+ "F","foo"
299
+ "B","bar""\\<>_@<b>{BAZ}"
300
+ EOB
301
+ end
302
+ @book.config['words_file'] = File.join(dir, 'words.csv')
303
+
304
+ io = StringIO.new
305
+ @builder.instance_eval{ @logger = ReVIEW::Logger.new(io) }
306
+ actual = compile_block('@<w>{F} @<w>{B} @<wb>{B} @<w>{N}')
307
+ assert_equal %Q(foo bar"\\<>_@<b>{BAZ} ★bar"\\<>_@<b>{BAZ}☆ [missing word: N]\n), actual
308
+ assert_match(/WARN -- : :1: word not bound: N/, io.string)
309
+ end
310
+ end
311
+
300
312
  def test_inline_unknown
301
313
  e = assert_raises(ReVIEW::ApplicationError) { compile_block "@<img>{n}\n" }
302
314
  assert_equal ':1: error: unknown image: n', e.message
@@ -35,8 +35,8 @@ EOB
35
35
  expect = <<-EOB
36
36
  <ul class="book-toc">
37
37
  <li><a href="index.html">TOP</a></li>
38
- <li><a href="./ch1.html">1 ch. 1</a></li>
39
- <li><a href="./ch2.html">2 ch. 2</a></li>
38
+ <li><a href="ch1.html">1 ch. 1</a></li>
39
+ <li><a href="ch2.html">2 ch. 2</a></li>
40
40
  </ul>
41
41
  EOB
42
42
  assert_equal expect, str
@@ -60,12 +60,12 @@ EOB
60
60
  <li><a href="index.html">TOP</a></li>
61
61
  <li>I part1
62
62
  <ul>
63
- <li><a href="./ch1.html">1 ch. 1</a></li>
63
+ <li><a href="ch1.html">1 ch. 1</a></li>
64
64
  </ul>
65
65
  </li>
66
66
  <li>II part2
67
67
  <ul>
68
- <li><a href="./ch2.html">2 ch. 2</a></li>
68
+ <li><a href="ch2.html">2 ch. 2</a></li>
69
69
  </ul>
70
70
  </li>
71
71
  </ul>
@@ -93,12 +93,12 @@ EOB
93
93
  <li><a href="index.html">TOP</a></li>
94
94
  <li><a href="p1.html">I This is PART1</a>
95
95
  <ul>
96
- <li><a href="./ch1.html">1 ch. 1</a></li>
96
+ <li><a href="ch1.html">1 ch. 1</a></li>
97
97
  </ul>
98
98
  </li>
99
99
  <li><a href="p2.html">II This is PART2</a>
100
100
  <ul>
101
- <li><a href="./ch2.html">2 ch. 2</a></li>
101
+ <li><a href="ch2.html">2 ch. 2</a></li>
102
102
  </ul>
103
103
  </li>
104
104
  </ul>
@@ -139,22 +139,22 @@ EOB
139
139
  expect = <<-EOB
140
140
  <ul class="book-toc">
141
141
  <li><a href="index.html">TOP</a></li>
142
- <li><a href="./pre1.html">PRE1</a></li>
143
- <li><a href="./pre2.html">PRE2</a></li>
142
+ <li><a href="pre1.html">PRE1</a></li>
143
+ <li><a href="pre2.html">PRE2</a></li>
144
144
  <li><a href="part1.html">I PART1</a>
145
145
  <ul>
146
- <li><a href="./ch1.html">1 ch. 1</a></li>
146
+ <li><a href="ch1.html">1 ch. 1</a></li>
147
147
  </ul>
148
148
  </li>
149
149
  <li><a href="part2.html">II PART2</a>
150
150
  <ul>
151
- <li><a href="./ch2.html">2 ch. 2</a></li>
151
+ <li><a href="ch2.html">2 ch. 2</a></li>
152
152
  </ul>
153
153
  </li>
154
- <li><a href="./app1.html">APP1</a></li>
155
- <li><a href="./app2.html">APP2</a></li>
156
- <li><a href="./post1.html">POST1</a></li>
157
- <li><a href="./post2.html">POST2</a></li>
154
+ <li><a href="app1.html">APP1</a></li>
155
+ <li><a href="app2.html">APP2</a></li>
156
+ <li><a href="post1.html">POST1</a></li>
157
+ <li><a href="post2.html">POST2</a></li>
158
158
  </ul>
159
159
  EOB
160
160
  assert_equal expect, str
@@ -0,0 +1,9 @@
1
+ *.dvi
2
+ *.aux
3
+ *.tmp
4
+ *.out
5
+ *.pdf
6
+ *.log
7
+ *~
8
+ *.synctex*
9
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2015--2017 Hironori Kitagawa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,18 @@
1
+ #`plistings` パッケージ
2
+
3
+ `plistings` パッケージは,`listings` パッケージを pLaTeX 上で用いる際の日本語対応処理を
4
+ 強化するためのパッケージである.
5
+ [LuaTeX-ja](https://osdn.jp/projects/luatex-ja/wiki/FrontPage) 中の `lltjp-listings.sty` を
6
+ ベースとしている.
7
+
8
+ ライセンスは今まで明記していなかったが,MIT License とした (2010-10-11).
9
+
10
+ ## 注意点(と,現在の制約)
11
+
12
+ * 実行には e-TeX 拡張が必要である(`\scantokens`, `\detokenize` 利用のため).
13
+ 最近の TeX Live, W32TeX では `platex` と打つと標準で e-TeX 拡張が有効になっている.
14
+ * 内部で文字コード 0 の文字 (`^^@`, NUL) を日本語処理命令として用いている.
15
+ そのため,NUL を含んだソースリストを出力することは出来なくなる.
16
+ * 「LaTeX へのエスケープ」内では,和文文字を含んだ制御綴が試験的にできるようになったが,
17
+ エスケープ内に書かれた NUL は自動的に取り除かれる.
18
+
@@ -0,0 +1,326 @@
1
+ %
2
+ % plistings.sty
3
+ %
4
+ % lltjp-listings.sty ベース,コード未整理
5
+
6
+ \NeedsTeXFormat{LaTeX2e}
7
+ \ProvidesPackage{plistings}[2015/12/07 v0.10 Japanese support of listings package]
8
+
9
+ %%%%%%%% Package options
10
+ \DeclareOption*{\PassOptionsToPackage{\CurrentOption}{listings}}
11
+ \ProcessOptions\relax
12
+ \RequirePackage{listings,etoolbox}
13
+
14
+ %%%%%%%% Japanese support
15
+ %% whether letter-space in a fixed mode box is doubled or not
16
+ \newif\if@ltj@lst@double
17
+ \lst@Key{doubleletterspace}f[t]{\lstKV@SetIf{#1}\if@ltj@lst@double}
18
+
19
+ % override \lst@FillFixed@
20
+ \def\lst@FillFixed@#1{%
21
+ \ifx\@empty#1\else\ltj@lst@hss#1\expandafter\lst@FillFixed@\fi}
22
+ \def\ltj@lst@hss@double{\lst@hss\lst@hss}
23
+
24
+ % 最下層の処理
25
+ \newif\if@ltj@lst@kanji
26
+ \lst@AddToHook{InitVars}{\@ltj@lst@kanjifalse}
27
+
28
+ \def\lst@AppendLetter{%
29
+ \ltj@lst@setletterflag\lst@Append}
30
+ \def\lst@AppendOther{%
31
+ \lst@ifletter\lst@Output\lst@letterfalse\fi\@ltj@lst@kanjifalse
32
+ \futurelet\lst@lastother\lst@Append}
33
+
34
+ \def\ltj@lst@setletterflag{%
35
+ \lst@ifletter
36
+ \if@ltj@lst@kanji\lst@Output\@ltj@lst@kanjifalse\fi
37
+ \else
38
+ \lst@lettertrue\if@ltj@lst@kanji\@ltj@lst@kanjifalse\else\lst@OutputOther\fi
39
+ \fi}
40
+
41
+ \def\ltj@lst@setkanjiflag{%
42
+ \lst@ifletter
43
+ \lst@Output
44
+ \else
45
+ \if@ltj@lst@kanji\else\lst@OutputOther\fi\lst@lettertrue
46
+ \fi\@ltj@lst@kanjitrue}
47
+
48
+ \def\ltj@lst@setopenflag{%
49
+ \lst@ifletter
50
+ \lst@letterfalse\lst@Output
51
+ \else
52
+ \if@ltj@lst@kanji\else\lst@OutputOther\fi
53
+ \fi\@ltj@lst@kanjitrue}
54
+
55
+ \def\ltj@lst@setcloseflag{%
56
+ \lst@ifletter\else\lst@lettertrue\fi\@ltj@lst@kanjitrue}
57
+
58
+ %%%% 和文文字の出力命令.
59
+ %%%% 和文文字の前にこれが前置されることになる.
60
+ \def\ltj@lst@ProcessJALetter#1{%
61
+ \lst@whitespacefalse
62
+ \ifnum`#1>255
63
+ \ifnum\postbreakpenalty`#1>0
64
+ \ltj@lst@setopenflag % 開き括弧類
65
+ \else
66
+ \ifnum\prebreakpenalty`#1>0
67
+ \ltj@lst@setcloseflag % 閉じ括弧類,句読点
68
+ \else
69
+ \ltj@lst@setkanjiflag % 通常の和文文字
70
+ \fi\fi
71
+ \advance\lst@length\@ne % 和文文字は通常の2倍の幅
72
+ \else
73
+ \ltj@lst@setletterflag
74
+ \fi
75
+ \lst@Append#1}
76
+
77
+
78
+ %%%% \lst@InsideConvert の処理内容変更
79
+ %%%% active 文字化に加え,^^@ を和文文字の前に前置
80
+ \def\ltj@lst@MakeActive#1{%
81
+ \let\lst@temp\@empty \ltj@lst@MakeActive@#1\relax}
82
+ \begingroup
83
+ \catcode`\^^A=\active
84
+ \catcode`\^^@=\active
85
+ \lowercase{%
86
+ \gdef\ltj@lst@MakeActive@#1{\let\lst@next\relax%
87
+ \ifx#1\relax
88
+ \else\let\lst@next\ltj@lst@MakeActive@
89
+ \ifnum`#1>255
90
+ \lst@lAddTo\lst@temp{^^@#1}%
91
+ \else
92
+ \lccode`\^^A=`#1
93
+ \lowercase{\lst@lAddTo\lst@temp{^^A}}%
94
+ \fi\fi\lst@next}}
95
+ \endgroup
96
+ \begingroup \lccode`\~=`\ \relax \lowercase{%
97
+ \gdef\lst@InsideConvert@#1 #2{%
98
+ \ltj@lst@MakeActive{#1}%
99
+ \ifx\@empty#2%
100
+ \lst@lExtend\lst@arg{\lst@temp}%
101
+ \else
102
+ \lst@lExtend\lst@arg{\lst@temp~}%
103
+ \expandafter\lst@InsideConvert@
104
+ \fi #2}
105
+ }\endgroup
106
+
107
+
108
+ %%%%%%%% \lstinline の再定義.
109
+ %%%% 引数を全部読み込み,\lst@InsideConvert で変換
110
+ \renewcommand\lstinline[1][]{%
111
+ \leavevmode\bgroup % \hbox\bgroup --> \bgroup
112
+ \def\lst@boxpos{b}%
113
+ \lsthk@PreSet\lstset{flexiblecolumns,#1}%
114
+ \lsthk@TextStyle
115
+ \@ifnextchar\bgroup \ltj@lst@InlineG \ltj@lstinline@}
116
+ \def\ltj@lstinline@#1{%
117
+ \edef\ltj@lst@temp{\the\catcode`#1}\lst@Init\relax\catcode`#1\ltj@lst@temp
118
+ \lst@Def{13}{\lst@DeInit\egroup \global\let\lst@inlinechars\@empty
119
+ \PackageError{Listings}{lstinline ended by EOL}\@ehc}%
120
+ \lst@InlineJ#1}
121
+ \def\ltj@lst@InlineG{%
122
+ \lst@Init\relax\edef\ltj@lst@temp{\the\catcode`\}}%
123
+ \catcode`\}=2 \catcode`\ =12\relax
124
+ \lst@Def{13}{\lst@DeInit\egroup \global\let\lst@inlinechars\@empty
125
+ \PackageError{Listings}{lstinline ended by EOL}\@ehc}%
126
+ \let\lst@arg\@empty\afterassignment\ltj@lst@InlineG@@\@temptokena}
127
+ \def\ltj@lst@InlineG@@{%
128
+ \catcode`\}=\ltj@lst@temp
129
+ \expandafter\expandafter\expandafter\lst@InsideConvert%
130
+ \expandafter{\the\@temptokena}\lst@arg\lst@DeInit\egroup}
131
+
132
+ %%%%%%%% \lstenv@process の再定義
133
+ %%%% 基本的にはインライン時と同様に全トークンを読み込み→\lst@InsideConvert で変換
134
+ %%%% その後,変換した中身は \scantokens で読み込み直される
135
+ \begingroup \lccode`\~=`\^^M\lowercase{%
136
+ \gdef\lstenv@Process#1{%
137
+ \ifx~#1%
138
+ \lstenv@DroppedWarning \let\lst@next\ltj@lstenv@ProcessM
139
+ \else\ifx^^J#1%
140
+ \lstenv@DroppedWarning \let\lst@next\lstenv@ProcessJ
141
+ \else
142
+ \let\lst@dropped#1\let\lst@next\lstenv@Process
143
+ \fi \fi
144
+ \lst@next}
145
+ }\endgroup
146
+ \begingroup\lccode`\[=`\{\lccode`\]=`\}\lccode`|=`\\\lowercase{%
147
+ \gdef\ltj@lstenv@ProcessM{%
148
+ \let\lst@arg\@empty
149
+ \edef\lst@temp{|end[\lstenv@name]}%
150
+ \expandafter\expandafter\expandafter\lst@InsideConvert%
151
+ \expandafter{\lst@temp}%
152
+ \@temptokena{%
153
+ \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter
154
+ \lst@SkipToFirst\expandafter\expandafter\expandafter\scantokens\expandafter{\lst@arg}%
155
+ }
156
+ \expandafter\expandafter\expandafter\toks@\expandafter{\lst@arg}
157
+ \expandafter\edef\expandafter\lst@temp\expandafter##\expandafter1\lst@arg
158
+ {%
159
+ \noexpand\let\noexpand\lst@arg\noexpand\@empty%
160
+ \noexpand\lst@InsideConvert{\noexpand##1}
161
+ \the\@temptokena\the\toks@
162
+ }%
163
+ \lst@temp}
164
+ }\endgroup
165
+
166
+ \def\lst@BeginDropInput#1{%
167
+ \lst@EnterMode{#1}%
168
+ {\lst@modetrue
169
+ \let\lst@OutputBox\@gobble
170
+ \let\lst@ifdropinput\iftrue
171
+ \let\lst@ProcessLetter\@gobble
172
+ \let\lst@ProcessDigit\@gobble
173
+ \let\lst@ProcessOther\@gobble
174
+ \let\lst@ProcessSpace\@empty
175
+ \let\lst@ProcessTabulator\@empty
176
+ \let\lst@ProcessFormFeed\@empty
177
+ \let\ltj@lst@ProcessJALetter\@gobble % added
178
+ }}
179
+
180
+
181
+ %%%% ^^@ を active 文字化 (\ltj@lst@ProcessJALetter)
182
+ \begingroup\catcode`\^^@=\active
183
+ \lst@AddTo\lst@SelectStdCharTable{\def^^@{\ltj@lst@ProcessJALetter}}
184
+ \endgroup
185
+ \lst@AddToHook{InitVars}{%
186
+ \catcode`\^^@=\active
187
+ \if@ltj@lst@double
188
+ \let\ltj@lst@hss=\ltj@lst@hss@double
189
+ \else
190
+ \let\ltj@lst@hss=\lst@hss
191
+ \fi
192
+ }
193
+
194
+ %%%% 白線対策のため,\lineskiplimit を負の値にする
195
+ \newif\ifltj@lst@frame@top
196
+ \newdimen\ltj@lst@frame@lslimit
197
+ \gdef\lst@frameInit{%
198
+ \ltj@lst@frame@toptrue
199
+ \ifx\lst@framelshape\@empty \let\lst@frameL\@empty \fi
200
+ \ifx\lst@framershape\@empty \let\lst@frameR\@empty \fi
201
+ \def\lst@framevrule{\vrule\@width\lst@framerulewidth\relax}%
202
+ \lst@ifframeround
203
+ \lst@frameCalcDimA\z@ \@getcirc\@tempdima
204
+ \@tempdimb\@tempdima \divide\@tempdimb\tw@
205
+ \advance\@tempdimb -\@wholewidth
206
+ \edef\lst@frametextsep{\the\@tempdimb}%
207
+ \edef\lst@framerulewidth{\the\@wholewidth}%
208
+ \lst@frameCalcDimA\@ne \@getcirc\@tempdima
209
+ \@tempdimb\@tempdima \divide\@tempdimb\tw@
210
+ \advance\@tempdimb -\tw@\@wholewidth
211
+ \advance\@tempdimb -\lst@frametextsep
212
+ \edef\lst@rulesep{\the\@tempdimb}%
213
+ \fi
214
+ \lst@frameMakeBoxV\lst@framebox{\ht\strutbox}{\dp\strutbox}%
215
+ %%%% ここから
216
+ \@tempdima\z@
217
+ \ifdim\ht\strutbox<\cht\@tempdima=\dimexpr\cht-\ht\strutbox\relax\fi
218
+ \ifdim\dp\strutbox<\cdp\advance\@tempdima=\dimexpr\cdp-\dp\strutbox\relax\fi
219
+ \ltj@lst@frame@lslimit=-\@tempdima
220
+ \def\lst@framelr{%
221
+ \ifltj@lst@frame@top\ltj@lst@frame@topfalse\else\lineskiplimit\ltj@lst@frame@lslimit\fi
222
+ \copy\lst@framebox}%
223
+ %%%% ここまで
224
+ \ifx\lst@frametshape\@empty\else
225
+ \lst@frameH T\lst@frametshape
226
+ \ifvoid\z@\else
227
+ \par\lst@parshape
228
+ \@tempdima-\baselineskip \advance\@tempdima\ht\z@
229
+ \ifdim\prevdepth<\@cclvi\p@\else
230
+ \advance\@tempdima\prevdepth
231
+ \fi
232
+ \ifdim\@tempdima<\z@
233
+ \vskip\@tempdima\vskip\lineskip
234
+ \fi
235
+ \noindent\box\z@\par
236
+ \lineskiplimit\maxdimen \lineskip\z@
237
+ \fi
238
+ \lst@frameSpreadV\lst@framextopmargin
239
+ \fi}
240
+
241
+ % lstinputlisting
242
+ % modified from jlisting.sty
243
+ \def\lst@InputListing#1{%
244
+ \begingroup
245
+ \lsthk@PreSet \gdef\lst@intname{#1}%
246
+ \expandafter\lstset\expandafter{\lst@set}%
247
+ \lsthk@DisplayStyle
248
+ \catcode\active=\active
249
+ \lst@Init\relax \let\lst@gobble\z@
250
+ \lst@SkipToFirst
251
+ \lst@ifprint \def\lst@next{\lst@get@filecontents{#1}}%
252
+ \else \let\lst@next\@empty
253
+ \fi
254
+ \lst@next
255
+ \lst@DeInit
256
+ \endgroup}
257
+ \newread\lst@inputfile
258
+ \def\lst@get@filecontents#1{%
259
+ \let\lst@filecontents\@empty
260
+ \openin\lst@inputfile=#1\relax
261
+ \let\@lst@get@filecontents@prevline\relax
262
+ \lst@get@filecontents@loop
263
+ \closein\lst@inputfile
264
+ \lst@filecontents\empty}
265
+ \def\lst@get@filecontents@loop{%
266
+ \read\lst@inputfile to\lst@temp
267
+ \let\lst@arg\@empty\expandafter\expandafter\expandafter\lst@InsideConvert\expandafter{\lst@temp}%
268
+ \ifx\@lst@get@filecontents@prevline\relax\else
269
+ \expandafter\expandafter\expandafter\def
270
+ \expandafter\expandafter\expandafter\lst@filecontents
271
+ \expandafter\expandafter\expandafter{%
272
+ \expandafter\lst@filecontents\@lst@get@filecontents@prevline}%
273
+ \fi
274
+ \let\@lst@get@filecontents@prevline\lst@arg
275
+ \ifeof\lst@inputfile\else
276
+ \expandafter\lst@get@filecontents@loop
277
+ \fi}
278
+
279
+ %%%%%%%% escape to \LaTeX
280
+ %%%% 一旦中身を全部取得した後で,^^@ ( = \ltj@lst@ProcessJALetter) を
281
+ %%%% トークン列から削除,その後 \scantokens で再読み込み
282
+ \lstloadaspects{escape}
283
+ \gdef\lst@Escape#1#2#3#4{%
284
+ \lst@CArgX #1\relax\lst@CDefX
285
+ {}%
286
+ {\lst@ifdropinput\else
287
+ \lst@TrackNewLines\lst@OutputLostSpace \lst@XPrintToken
288
+ \lst@InterruptModes
289
+ \lst@EnterMode{\lst@TeXmode}{\lst@modetrue}%
290
+ \ifx\^^M#2%
291
+ \lst@CArg #2\relax\lst@ActiveCDefX
292
+ {}%
293
+ {\lst@escapeend #4\lst@LeaveAllModes\lst@ReenterModes}%
294
+ {\ltj@lst@MProcessListing}%
295
+ \else
296
+ \lst@CArg #2\relax\lst@ActiveCDefX
297
+ {}%
298
+ {\lst@escapeend #4\lst@LeaveAllModes\lst@ReenterModes
299
+ \lst@newlines\z@ \lst@whitespacefalse}%
300
+ {}%
301
+ \fi%
302
+ \ltj@lst@escape@setup#2
303
+ #3\lst@escapebegin\expandafter\lst@next%
304
+ \fi}%
305
+ {}}
306
+ \def\ltj@lst@escape@setup#1{%
307
+ \begingroup\lccode`\~=`#1\lowercase{%
308
+ \gdef\lst@next##1~{%
309
+ \let\lst@arg\@empty\ltj@lst@remove@jacmd{##1}%
310
+ \expandafter\expandafter\expandafter\scantokens\expandafter{\lst@arg}%
311
+ ~}%
312
+ }\endgroup
313
+ }
314
+
315
+ \begingroup
316
+ \catcode`\^^@=12 %
317
+ \gdef\ltj@lst@remove@jacmd#1{%
318
+ \expandafter\ltj@lst@remove@jacmd@\detokenize{#1}^^@\@nil^^@}
319
+ \gdef\ltj@lst@remove@jacmd@#1^^@{%
320
+ \ifx#1\@nil\else
321
+ \lst@lAddTo\lst@arg{#1}%
322
+ \expandafter\ltj@lst@remove@jacmd@
323
+ \fi}
324
+ \endgroup
325
+
326
+ \endinput