diff --git a/lib/review/book/base.rb b/lib/review/book/base.rb index 582f5c35d..eb64e0b89 100644 --- a/lib/review/book/base.rb +++ b/lib/review/book/base.rb @@ -29,7 +29,6 @@ def initialize(basedir = '.') @chapter_index = nil @config = ReVIEW::Configure.values @catalog = nil - @read_part = nil @warn_old_files = {} # XXX for checking CHAPS, PREDEF, POSTDEF @basedir_seen = {} update_rubyenv @@ -202,7 +201,7 @@ def read_chaps if catalog catalog.chaps else - read_file(config['chapter_file']) + read_file(config['chapter_file']).split("\n") end end @@ -210,7 +209,7 @@ def read_predef if catalog catalog.predef else - read_file(config['predef_file']) + read_file(config['predef_file']).split("\n") end end @@ -218,7 +217,7 @@ def read_appendix if catalog catalog.appendix else - read_file(config['postdef_file']) # for backward compatibility + read_file(config['postdef_file']).split("\n") # for backward compatibility end end @@ -226,17 +225,15 @@ def read_postdef if catalog catalog.postdef else - '' + [] end end def read_part - return @read_part if @read_part - if catalog - @read_part = catalog.parts + catalog.parts else - @read_part = File.read(File.join(@basedir, config['part_file'])) + File.read(File.join(@basedir, config['part_file'])).split("\n") end end @@ -258,7 +255,7 @@ def bib_exist? def prefaces if catalog - return mkpart_from_namelist(catalog.predef.split("\n")) + return mkpart_from_namelist(catalog.predef) end begin @@ -273,7 +270,7 @@ def prefaces def appendix if catalog - names = catalog.appendix.split("\n") + names = catalog.appendix chaps = names.each_with_index.map { |n, idx| mkchap_ifexist(n, idx) }.compact return mkpart(chaps) end @@ -290,7 +287,7 @@ def appendix def postscripts if catalog - mkpart_from_namelist(catalog.postdef.split("\n")) + mkpart_from_namelist(catalog.postdef) end end @@ -324,7 +321,7 @@ def parse_chapters chap = Chapter.new(self, num += 1, chap, File.join(contentdir, chap)) chap end - Part.new(self, part += 1, chaps, read_part.split("\n")[part - 1]) + Part.new(self, part += 1, chaps, read_part[part - 1]) else chap = Chapter.new(self, num += 1, entry, File.join(contentdir, entry)) if chap.number @@ -337,12 +334,11 @@ def parse_chapters end end - chap = read_chaps. - strip.lines.map(&:strip).join("\n").split(/\n{2,}/). + chap = read_chaps.map(&:strip).join("\n").split(/\n{2,}/). map do |part_chunk| chaps = part_chunk.split.map { |chapid| Chapter.new(self, num += 1, chapid, File.join(contentdir, chapid)) } - if part_exist? && read_part.split("\n").size > part - Part.new(self, part += 1, chaps, read_part.split("\n")[part - 1]) + if part_exist? && read_part.size > part + Part.new(self, part += 1, chaps, read_part[part - 1]) else Part.new(self, nil, chaps) end diff --git a/lib/review/book/chapter.rb b/lib/review/book/chapter.rb index 6f472042d..072c672fb 100644 --- a/lib/review/book/chapter.rb +++ b/lib/review/book/chapter.rb @@ -125,7 +125,7 @@ def on_postdef? private def on_file?(contents) - contents.lines.map(&:strip).include?("#{id}#{@book.ext}") + contents.map(&:strip).include?("#{id}#{@book.ext}") end # backward compatibility diff --git a/lib/review/builder.rb b/lib/review/builder.rb index 6386870c4..9adc889f7 100644 --- a/lib/review/builder.rb +++ b/lib/review/builder.rb @@ -71,6 +71,10 @@ def builder_init_file end private :builder_init_file + def highlight? + false + end + def result @output.string end @@ -162,7 +166,7 @@ def table(lines, id = nil, caption = nil) error "no such table: #{id}" end table_begin(rows.first.size) - table_tr(sepidx, rows) + table_rows(sepidx, rows) table_end end @@ -181,7 +185,7 @@ def parse_table_rows(lines) [sepidx, rows] end - def table_tr(sepidx, rows) + def table_rows(sepidx, rows) if sepidx sepidx.times do tr(rows.shift.map { |s| th(s) }) @@ -410,7 +414,12 @@ def inline_w(s) end def inline_wb(s) - inline_b(unescape(inline_w(s))) + translated = @dictionary[s] + if translated + inline_b(translated) + else + inline_b("[missing word: #{s}]") + end end def raw(str) @@ -429,9 +438,9 @@ def embed(lines, arg = nil) if arg builders = arg.gsub(/^\s*\|/, '').gsub(/\|\s*$/, '').gsub(/\s/, '').split(',') c = target_name - print lines.join if builders.include?(c) + print lines.join("\n") + "\n" if builders.include?(c) else - print lines.join + print lines.join("\n") + "\n" end end @@ -510,13 +519,13 @@ def graph(lines, id, command, caption = '') file = "#{id}.#{image_ext}" file_path = File.join(dir, file) - line = self.unescape(lines.join("\n")) + content = lines.join("\n") + "\n" tf = Tempfile.new('review_graph') - tf.puts line + tf.puts content tf.close begin - file_path = send("graph_#{command}".to_sym, id, file_path, line, tf.path) + file_path = send("graph_#{command}".to_sym, id, file_path, content, tf.path) ensure tf.unlink end @@ -640,9 +649,5 @@ def detab(str, num = nil) def escape(str) str end - - def unescape(str) - str - end end end # module ReVIEW diff --git a/lib/review/catalog.rb b/lib/review/catalog.rb index b74afbdb9..9bdb3a9fa 100644 --- a/lib/review/catalog.rb +++ b/lib/review/catalog.rb @@ -12,12 +12,11 @@ def initialize(file) end def predef - return '' unless @yaml['PREDEF'] - @yaml['PREDEF'].join("\n") + @yaml['PREDEF'] || [] end def chaps - return '' unless @yaml['CHAPS'] + return [] unless @yaml['CHAPS'] @yaml['CHAPS'].map do |entry| if entry.is_a?(String) @@ -25,11 +24,11 @@ def chaps elsif entry.is_a?(Hash) entry.values # chaps in a part end - end.flatten.join("\n") + end.flatten end def parts - return '' unless @yaml['CHAPS'] + return [] unless @yaml['CHAPS'] part_list = @yaml['CHAPS'].map do |entry| if entry.is_a?(Hash) @@ -37,7 +36,7 @@ def parts end end - part_list.flatten.compact.join("\n") + part_list.flatten.compact end def replace_part(old_name, new_name) @@ -55,13 +54,11 @@ def parts_with_chaps end def appendix - return '' unless @yaml['APPENDIX'] - @yaml['APPENDIX'].join("\n") + @yaml['APPENDIX'] || [] end def postdef - return '' unless @yaml['POSTDEF'] - @yaml['POSTDEF'].join("\n") + @yaml['POSTDEF'] || [] end def to_s @@ -71,7 +68,7 @@ def to_s def validate!(config, basedir) filenames = [] if predef.present? - filenames.concat(predef.split(/\n/)) + filenames.concat(predef) end parts_with_chaps.each do |chap| if chap.is_a?(Hash) @@ -86,10 +83,10 @@ def validate!(config, basedir) end end if appendix.present? - filenames.concat(appendix.split(/\n/)) + filenames.concat(appendix) end if postdef.present? - filenames.concat(postdef.split(/\n/)) + filenames.concat(postdef) end filenames.each do |filename| refile = File.join(basedir, config['contentdir'], filename) diff --git a/lib/review/compiler.rb b/lib/review/compiler.rb index a0dd9ef41..ffe63ee27 100644 --- a/lib/review/compiler.rb +++ b/lib/review/compiler.rb @@ -16,12 +16,25 @@ module ReVIEW class Compiler def initialize(strategy) @strategy = strategy + + ## commands which do not parse block lines in compiler + @non_parsed_commands = %i[embed texequation graph] + + ## to decide escaping/non-escaping for text + @command_name_stack = [] end attr_reader :strategy def compile(chap) @chapter = chap + @non_parsed_commands = %i[embed texequation graph] + if @strategy.highlight? + @non_escaped_commands = %i[list emlist listnum emlistnum cmd] + else + @non_escaped_commands = [] + end + @command_name_stack = [] do_compile @strategy.result end @@ -235,14 +248,17 @@ def do_compile f.gets error 'block end seen but not opened' when %r{\A//[a-z]+} + # @command_name_stack.push(name) ## <- move into read_command() to use name name, args, lines = read_command(f) syntax = syntax_descriptor(name) unless syntax error "unknown command: //#{name}" compile_unknown_command(args, lines) + @command_name_stack.pop next end compile_command(syntax, args, lines) + @command_name_stack.pop when %r{\A//} line = f.gets warn "`//' seen but is not valid command: #{line.strip.inspect}" @@ -422,7 +438,8 @@ def compile_paragraph(f) def read_command(f) line = f.gets name = line.slice(/[a-z]+/).to_sym - ignore_inline = (name == :embed) + ignore_inline = @non_parsed_commands.include?(name) + @command_name_stack.push(name) args = parse_args(line.sub(%r{\A//[a-z]+}, '').rstrip.chomp('{'), name) @strategy.doc_status[name] = true lines = block_open?(line) ? read_block(f, ignore_inline) : nil @@ -439,9 +456,9 @@ def read_block(f, ignore_inline) buf = [] f.until_match(%r{\A//\}}) do |line| if ignore_inline - buf.push(line) + buf.push(line.chomp) elsif line !~ /\A\#@/ - buf.push(text(line.rstrip)) + buf.push(text(line.rstrip, true)) end end unless %r{\A//\}} =~ f.peek @@ -527,7 +544,12 @@ def revert_replace_fence(str) str.gsub("\x01", '@').gsub("\x02", '\\').gsub("\x03", '{').gsub("\x04", '}') end - def text(str) + def in_non_escaped_command? + current_command = @command_name_stack.last + current_command && @non_escaped_commands.include?(current_command) + end + + def text(str, block_mode = false) return '' if str.empty? words = replace_fence(str).split(/(@<\w+>\{(?:[^\}\\]|\\.)*?\})/, -1) words.each do |w| @@ -535,10 +557,15 @@ def text(str) error "`@' seen but is not valid inline op: #{w}" end end - result = @strategy.nofunc_text(revert_replace_fence(words.shift)) + result = '' until words.empty? + if in_non_escaped_command? && block_mode + result << revert_replace_fence(words.shift) + else + result << @strategy.nofunc_text(revert_replace_fence(words.shift)) + end + break if words.empty? result << compile_inline(revert_replace_fence(words.shift.gsub(/\\\}/, '}').gsub(/\\\\/, '\\'))) - result << @strategy.nofunc_text(revert_replace_fence(words.shift)) end result rescue => e diff --git a/lib/review/htmlbuilder.rb b/lib/review/htmlbuilder.rb index 8f7177fc0..d88462b2b 100644 --- a/lib/review/htmlbuilder.rb +++ b/lib/review/htmlbuilder.rb @@ -565,11 +565,11 @@ def texequation_body(lines) require 'math_ml' require 'math_ml/symbol/character_reference' p = MathML::LaTeX::Parser.new(symbol: MathML::Symbol::CharacterReference) - puts p.parse(unescape(lines.join("\n")), true) + print p.parse(lines.join("\n") + "\n", true) elsif @book.config['imgmath'] fontsize = @book.config['imgmath_options']['fontsize'].to_f lineheight = @book.config['imgmath_options']['lineheight'].to_f - math_str = "\\begin{equation*}\n\\fontsize{#{fontsize}}{#{lineheight}}\\selectfont\n#{unescape(lines.join("\n"))}\n\\end{equation*}\n" + math_str = "\\begin{equation*}\n\\fontsize{#{fontsize}}{#{lineheight}}\\selectfont\n#{lines.join("\n")}\n\\end{equation*}\n" key = Digest::SHA256.hexdigest(math_str) math_dir = File.join(@book.config['imagedir'], '_review_math') Dir.mkdir(math_dir) unless Dir.exist?(math_dir) @@ -642,22 +642,12 @@ def image_header(id, caption) end def table(lines, id = nil, caption = nil) - sepidx, rows = parse_table_rows(lines) if id puts %Q(
) else puts %Q(
) end - begin - if caption.present? - table_header(id, caption) - end - rescue KeyError - error "no such table: #{id}" - end - table_begin(rows.first.size) - table_tr(sepidx, rows) - table_end + super(lines, id, caption) puts '
' end diff --git a/lib/review/htmlutils.rb b/lib/review/htmlutils.rb index 7623b9bc4..9dba1f11c 100644 --- a/lib/review/htmlutils.rb +++ b/lib/review/htmlutils.rb @@ -41,7 +41,7 @@ def escape_comment(str) end def highlight? - @book.config['highlight'] && + @book && @book.config['highlight'] && @book.config['highlight']['html'] end @@ -82,7 +82,7 @@ def highlight_pygments(ops) begin require 'pygments' begin - Pygments.highlight(unescape(body), + Pygments.highlight(body, options: options, formatter: format, lexer: lexer) @@ -128,8 +128,7 @@ def highlight_rouge(ops) return body end - text = unescape(body) - formatter.format(lexer.lex(text)) + formatter.format(lexer.lex(body)) end def normalize_id(id) diff --git a/lib/review/idgxmlbuilder.rb b/lib/review/idgxmlbuilder.rb index d226e19cf..cda41921c 100644 --- a/lib/review/idgxmlbuilder.rb +++ b/lib/review/idgxmlbuilder.rb @@ -460,7 +460,7 @@ def texequation(lines, id = nil, caption = '') puts %Q() puts '
'
-      puts lines.join("\n")
+      print lines.join("\n")
       puts '
' puts '
' @@ -490,7 +490,7 @@ def table(lines, id = nil, caption = nil) else print %Q() end - table_tr(sepidx, rows) + table_rows(sepidx, rows) puts '' @tsize = nil end @@ -515,7 +515,7 @@ def parse_table_rows(lines) [sepidx, rows] end - def table_tr(sepidx, rows) + def table_rows(sepidx, rows) cellwidth = [] if @tablewidth if @tsize.nil? diff --git a/lib/review/latexbuilder.rb b/lib/review/latexbuilder.rb index 113eaea47..0b0285e92 100644 --- a/lib/review/latexbuilder.rb +++ b/lib/review/latexbuilder.rb @@ -323,17 +323,30 @@ def read(lines) alias_method :lead, :read + def highlight? + @book.config['highlight'] && + @book.config['highlight']['latex'] + end + def highlight_listings? @book.config['highlight'] && @book.config['highlight']['latex'] == 'listings' end private :highlight_listings? + def code_line(_type, line, _idx, _id, _caption, _lang) + detab(line) + "\n" + end + + def code_line_num(_type, line, first_line_num, idx, _id, _caption, _lang) + detab((idx + first_line_num).to_s.rjust(2) + ': ' + line) + "\n" + end + def emlist(lines, caption = nil, lang = nil) blank if highlight_listings? common_code_block_lst(nil, lines, 'reviewemlistlst', 'title', caption, lang) else - common_code_block(nil, lines, 'reviewemlist', caption, lang) { |line, _idx| detab(line) + "\n" } + common_code_block(nil, lines, 'reviewemlist', caption, lang) { |line, idx| code_line('emlist', line, idx, nil, caption, lang) } end end @@ -343,7 +356,7 @@ def emlistnum(lines, caption = nil, lang = nil) if highlight_listings? common_code_block_lst(nil, lines, 'reviewemlistnumlst', 'title', caption, lang, first_line_num: first_line_num) else - common_code_block(nil, lines, 'reviewemlist', caption, lang) { |line, idx| detab((idx + first_line_num).to_s.rjust(2) + ': ' + line) + "\n" } + common_code_block(nil, lines, 'reviewemlist', caption, lang) { |line, idx| code_line_num('emlistnum', line, first_line_num, idx, nil, caption, lang) } end end @@ -352,7 +365,7 @@ def list(lines, id, caption, lang = nil) if highlight_listings? common_code_block_lst(id, lines, 'reviewlistlst', 'caption', caption, lang) else - common_code_block(id, lines, 'reviewlist', caption, lang) { |line, _idx| detab(line) + "\n" } + common_code_block(id, lines, 'reviewlist', caption, lang) { |line, idx| code_line('list', line, idx, id, caption, lang) } end end @@ -362,7 +375,7 @@ def listnum(lines, id, caption, lang = nil) if highlight_listings? common_code_block_lst(id, lines, 'reviewlistnumlst', 'caption', caption, lang, first_line_num: first_line_num) else - common_code_block(id, lines, 'reviewlist', caption, lang) { |line, idx| detab((idx + first_line_num).to_s.rjust(2) + ': ' + line) + "\n" } + common_code_block(id, lines, 'reviewlist', caption, lang) { |line, idx| code_line_num('listnum', line, first_line_num, idx, id, caption, lang) } end end @@ -371,7 +384,7 @@ def cmd(lines, caption = nil, lang = nil) common_code_block_lst(nil, lines, 'reviewcmdlst', 'title', caption, lang) else blank - common_code_block(nil, lines, 'reviewcmd', caption, lang) { |line, _idx| detab(line) + "\n" } + common_code_block(nil, lines, 'reviewcmd', caption, lang) { |line, idx| code_line('cmd', line, idx, nil, caption, lang) } end end @@ -413,7 +426,7 @@ def common_code_block_lst(_id, lines, command, title, caption, lang, first_line_ if title == 'title' && caption.blank? && @book.config.check_version('2', exception: false) print '\vspace{-1.5em}' end - body = lines.inject('') { |i, j| i + detab(unescape(j)) + "\n" } + body = lines.inject('') { |i, j| i + detab(j) + "\n" } args = make_code_block_args(title, caption, lang, first_line_num: first_line_num) puts %Q(\\begin{#{command}}[#{args}]) print body @@ -448,7 +461,7 @@ def source(lines, caption = nil, lang = nil) if highlight_listings? common_code_block_lst(nil, lines, 'reviewsourcelst', 'title', caption, lang) else - common_code_block(nil, lines, 'reviewsource', caption, lang) { |line, _idx| detab(line) + "\n" } + common_code_block(nil, lines, 'reviewsource', caption, lang) { |line, idx| code_line('source', line, idx, nil, caption, lang) } end end @@ -608,7 +621,7 @@ def table(lines, id = nil, caption = nil) error "no such table: #{id}" end table_begin(rows.first.size) - table_tr(sepidx, rows) + table_rows(sepidx, rows) table_end if caption.present? puts '\end{table}' @@ -616,7 +629,7 @@ def table(lines, id = nil, caption = nil) blank end - def table_tr(sepidx, rows) + def table_rows(sepidx, rows) if sepidx sepidx.times do cno = -1 @@ -838,7 +851,7 @@ def texequation(lines, id = nil, caption = '') puts macro('begin', 'equation*') lines.each do |line| - puts unescape(line) + puts line end puts macro('end', 'equation*') diff --git a/lib/review/markdownbuilder.rb b/lib/review/markdownbuilder.rb index 3fff4e3ac..686fda8f1 100644 --- a/lib/review/markdownbuilder.rb +++ b/lib/review/markdownbuilder.rb @@ -252,19 +252,7 @@ def cmd(lines, caption = nil) puts '```' end - def table(lines, id = nil, caption = nil) - sepidx, rows = parse_table_rows(lines) - begin - table_header(id, caption) unless caption.nil? - rescue KeyError - error "no such table: #{id}" - end - table_begin(rows.first.size) - table_tr(sepidx, rows) - table_end - end - - def table_tr(sepidx, rows) + def table_rows(sepidx, rows) if sepidx sepidx.times do tr(rows.shift.map { |s| th(s) }) diff --git a/lib/review/plaintextbuilder.rb b/lib/review/plaintextbuilder.rb index 459a58d3a..5e565df9b 100644 --- a/lib/review/plaintextbuilder.rb +++ b/lib/review/plaintextbuilder.rb @@ -243,18 +243,11 @@ def texequation_header(id, caption) end end - def table(lines, id = nil, caption = nil) - sepidx, rows = parse_table_rows(lines) - blank - - begin - table_header(id, caption) if caption.present? - rescue KeyError - error "no such table: #{id}" + def table(lines, id = nil, caption = nil, noblank = nil) + unless noblank + blank end - table_begin(rows.first.size) - table_tr(sepidx, rows) - table_end + super(lines, id, caption) end def table_header(id, caption) diff --git a/lib/review/rstbuilder.rb b/lib/review/rstbuilder.rb index c2a88b7bd..5fdea23de 100644 --- a/lib/review/rstbuilder.rb +++ b/lib/review/rstbuilder.rb @@ -103,13 +103,13 @@ def headline(level, label, caption) blank end puts '=' * caption.size * 2 - when 2 then + when 2 p = '=' - when 3 then + when 3 p = '-' - when 4 then + when 4 p = '`' - when 5 then + when 5 p = '~' end diff --git a/lib/review/topbuilder.rb b/lib/review/topbuilder.rb index fd14386c3..a8aad9e76 100644 --- a/lib/review/topbuilder.rb +++ b/lib/review/topbuilder.rb @@ -203,7 +203,7 @@ def texequation(lines, id = nil, caption = '') if @book.config['imgmath'] fontsize = @book.config['imgmath_options']['fontsize'].to_f lineheight = @book.config['imgmath_options']['lineheight'].to_f - math_str = "\\begin{equation*}\n\\fontsize{#{fontsize}}{#{lineheight}}\\selectfont\n#{unescape(lines.join("\n"))}\n\\end{equation*}\n" + math_str = "\\begin{equation*}\n\\fontsize{#{fontsize}}{#{lineheight}}\\selectfont\n#{lines.join("\n")}\n\\end{equation*}\n" key = Digest::SHA256.hexdigest(math_str) math_dir = File.join(@book.config['imagedir'], '_review_math_text') Dir.mkdir(math_dir) unless Dir.exist?(math_dir) @@ -229,19 +229,9 @@ def texequation_header(id, caption) end def table(lines, id = nil, caption = nil) - sepidx, rows = parse_table_rows(lines) blank puts "◆→開始:#{@titles['table']}←◆" - - begin - table_header(id, caption) if caption.present? - rescue KeyError - error "no such table: #{id}" - end - table_begin(rows.first.size) - table_tr(sepidx, rows) - table_end - + super(lines, id, caption, true) puts "◆→終了:#{@titles['table']}←◆" blank end diff --git a/templates/latex/review-jlreq/review-base.sty b/templates/latex/review-jlreq/review-base.sty index 3e7f34e14..af2d8de07 100644 --- a/templates/latex/review-jlreq/review-base.sty +++ b/templates/latex/review-jlreq/review-base.sty @@ -32,8 +32,8 @@ {\end{alltt}\end{tcolorbox}} \newenvironment{reviewcmd}{% - \begin{tcolorbox}[skin=enhanced jigsaw,breakable,colback=black!99,colframe=black!99,boxrule=0mm,arc=0mm]\begin{alltt}\begingroup\color{white}\ignorespaces}% - {\endgroup\end{alltt}\end{tcolorbox}} + \begin{tcolorbox}[skin=enhanced jigsaw,breakable,colback=black!99,coltext=white,colframe=black!99,boxrule=0mm,arc=0mm]\begin{alltt}}% + {\end{alltt}\end{tcolorbox}} % 図 \newenvironment{reviewimage}{% @@ -115,7 +115,7 @@ \newcommand{\reviewlistref}[1]{\review@intn@list #1} \newcommand{\reviewequationref}[1]{\review@intn@equation #1} \newcommand{\reviewbibref}[2]{#1} -\newcommand{\reviewcolumnref}[2]{\review@intn@columnname #1} +\newcommand{\reviewcolumnref}[2]{#1} \newcommand{\reviewsecref}[2]{#1} \renewcommand{\contentsname}{\review@toctitle} diff --git a/templates/latex/review-jsbook/README.md b/templates/latex/review-jsbook/README.md index 522f87327..42e7796d5 100644 --- a/templates/latex/review-jsbook/README.md +++ b/templates/latex/review-jsbook/README.md @@ -125,3 +125,42 @@ texdocumentclass: ["review-jsbook", "クラスオプションたち(省略可 * jsbook.cls のクラスオプション `uplatex`:これまで texdocumentclass に指定が必要だった `uplatex` オプションは不要となっています。 * jsbook.cls のクラスオプション `nomag`:用紙サイズや版面設計は、review-jsbook.cls 側で行います。 * hyperref パッケージ:あらかじめ hyperref パッケージを組み込んでおり、`media` オプションにより用途別で挙動を制御します。 + +### 既存の jsbook.cls のオプションの扱い + +review-jsbook.cls は jsbook.cls を包んでおり、一部の jsbook.cls のクラスオプションはそのまま指定可能です。 + + * `oneside`: 奇数ページ・偶数ページで柱やページ番号などを同じ体裁にします。review-jsbook.cls にも有効ですが、review-style.sty でこれを打ち消し奇数・偶数で別の見た目にするデザイン (fancyhdr) が定義されているので、review-style.sty も調整する必要があります。 + * `twoside`: 奇数ページ・偶数ページで柱やページ番号などを別の体裁にします (デフォルト)。 + * `vartwoside`: twoside とおおむね同じですが、傍注が小口ではなく常に右側になります。Re:VIEW のデフォルトでは傍注は使用していないので、効果は通常表れません。 + * `onecolumn`: 1段組の体裁にします (デフォルト)。 + * `twocolumn`: 2段組の体裁にします。 + * `openright`: 章の始まりを右ページ (奇数ページ) にします (デフォルト)。前の章が右ページで終わった場合には、白紙のページが1ページ挿入されます。 + * `openleft`: 章の始まりを左ページ (偶数ページ) にします。前の章が左ページで終わった場合には、白紙のページが1ページ挿入されます。 + * `openany`: 章の始まりを左右どちらのページからでも始めます。 + * `draft`: 確認作業のために、overfull box が起きた箇所の行末に罫線を引き、画像は実際に貼り付けずにボックスとファイル名だけを表記するようにします。 + * `final`: 上記の draft の処理を行いません (デフォルト)。 + * `leqno`: 数式の番号を右ではなく左側に置きます。ただし Re:VIEW では LaTeX のやり方での採番付き数式を作っていないので、効果は通常表れません。 + * `fleqn`: 数式をデフォルトの左右中央ではなく、左側に配置します。 + * `english`: 英語ドキュメント向けに、字下げをなくしたり、「章」や「目次」などの定型の文字列を英語化します。しかし、Re:VIEW では定型文字列はロケールファイルで処理しており、ほとんどは無視されます。 + * `jslogo`: 「LaTeX」等のロゴを置き換えます (デフォルト)。 + * `nojslogo`: ロゴを置き換えません。 + * `report`: oneside と openany の両方と同じ効果を持ちます。 + * `landscape`: 用紙を横長で使います。review-jsbook.cls のクラスオプションで基本版面設計をやり直す必要があることに注意してください。 + +jsbook.cls の以下のクラスオプションは挙動が異なります。代わりに review-jsbook.cls のクラスオプションを利用してください。 + + * `8pt`・`9pt`・`10pt`・`11pt`・`12pt`・`14pt`・`17pt`・`20pt`・`21pt`・`25pt`・`30pt`・`36pt`・`43pt`・`12Q`・`14Q`・`10ptj`・`10.5ptj`・`11ptj`・`12ptj`: 基本文字のサイズを指定します。そのまま review-jsbook.cls の fontsize に渡されますが、上記の fontsize クラスオプションの説明にあるとおり丸められます。 + * `tombow`・`tombo`・`mentuke`: トンボや塗り足しを作成しますが、これらは PDF 入稿に求められる正しいデジタルトンボ情報を入れないので使用してはなりません。review-jsbook.cls の `media=print` を使ってください。 + * `a4paper`・`a5paper`・`b5paper`・`b4paper`・`letterpaper`: 紙サイズを指定します。誤りではありませんが、review-jsbook.cls の paper クラスオプションを使うほうが妥当です。 + +jsbook.cls の以下のクラスオプションは無視またはエラーになります。 + + * `uplatex`: 暗黙に指定されるので無視されます。 + * `autodetect-engine`: pLaTeX/upLaTeX を自動判別するオプションですが、Re:VIEW では review-jsbook 利用時に upLaTeX を暗黙に前提としているので無視されます。 + * `papersize`: dvips などに紙サイズ情報を与えるオプションですが、Re:VIEW ではこれを利用しないので、結果的に無視されます。 + * `titlepage`・`notitlepage`: 表題の独立ページ化の有無ですが、Re:VIEW では表題を利用していないため、結果的に無視されます。 + * `usemag`・`nomag`・`nomag*`: 用紙サイズと版面設計は review-jsbook.cls のクラスオプションを使うため、無視されます。 + * `a4j`・`a5j`・`b4j`・`b5j`・`winjis`・`mingoth`: これらは無効としており、エラーになります。review-jsbook.cls のクラスオプションを利用してください。 + * `jis`: jis フォントメトリックスを使う指定ですが、通常の環境ではコンパイルエラーになります。 + * `disablejfam`: 数式内の利用フォント数を増やすために、数式内の日本語文字を使わないようにする指定ですが、Re:VIEW を利用する上では単にエラーを誘発するだけでしょう。 diff --git a/templates/latex/review-jsbook/review-base.sty b/templates/latex/review-jsbook/review-base.sty index a4945f274..b21baaa79 100644 --- a/templates/latex/review-jsbook/review-base.sty +++ b/templates/latex/review-jsbook/review-base.sty @@ -205,7 +205,7 @@ \newcommand{\reviewlistref}[1]{\review@intn@list #1} \newcommand{\reviewequationref}[1]{\review@intn@equation #1} \newcommand{\reviewbibref}[2]{#1} -\newcommand{\reviewcolumnref}[2]{\review@intn@columnname #1} +\newcommand{\reviewcolumnref}[2]{#1} \newcommand{\reviewsecref}[2]{#1} \newenvironment{reviewpart}{% diff --git a/test/test_book.rb b/test/test_book.rb index 97a18d6b6..a8bb52fa2 100644 --- a/test/test_book.rb +++ b/test/test_book.rb @@ -32,7 +32,7 @@ def test_ext def test_read_chaps Dir.mktmpdir do |dir| book = Book::Base.new(dir) - assert_equal '', book.read_chaps + assert_equal [], book.read_chaps chaps_path = File.join(dir, 'CHAPS') re1_path = File.join(dir, "123#{book.ext}") @@ -42,16 +42,16 @@ def test_read_chaps File.open(re1_path, 'w') { |o| o.print "123\n" } File.open(re2_path, 'w') { |o| o.print "456\n" } - assert_equal "abc\n", book.read_chaps + assert_equal ['abc'], book.read_chaps File.unlink(chaps_path) - assert_equal "#{re1_path}\n#{re2_path}", book.read_chaps + assert_equal [re1_path, re2_path], book.read_chaps File.unlink(re1_path) - assert_equal re2_path, book.read_chaps + assert_equal [re2_path], book.read_chaps File.unlink(re2_path) - assert_equal '', book.read_chaps + assert_equal [], book.read_chaps end end @@ -68,17 +68,18 @@ def test_read_part File.open(chaps_path, 'w') { |o| o.print chaps_content } assert book.part_exist? - assert_equal chaps_content, book.read_part + assert_equal %w[abc], book.read_part + ## do not cache PART data File.open(chaps_path, 'w') { |o| o.print "XYZ\n" } - assert_equal chaps_content, book.read_part + assert_equal %w[XYZ], book.read_part end end def test_read_appendix Dir.mktmpdir do |dir| book = Book::Base.new(dir) - assert_equal '', book.read_appendix + assert_equal [], book.read_appendix post_path = File.join(dir, 'POSTDEF') re1_path = File.join(dir, "123#{book.ext}") @@ -88,23 +89,23 @@ def test_read_appendix File.open(re1_path, 'w') { |o| o.print "123\n" } File.open(re2_path, 'w') { |o| o.print "456\n" } - assert_equal "abc\n", book.read_appendix + assert_equal ['abc'], book.read_appendix File.unlink(post_path) - assert_equal "#{re1_path}\n#{re2_path}", book.read_appendix + assert_equal [re1_path, re2_path], book.read_appendix File.unlink(re1_path) - assert_equal re2_path, book.read_appendix + assert_equal [re2_path], book.read_appendix File.unlink(re2_path) - assert_equal '', book.read_appendix + assert_equal [], book.read_appendix end end def test_read_postdef Dir.mktmpdir do |dir| book = Book::Base.new(dir) - assert_equal '', book.read_postdef + assert_equal [], book.read_postdef post_path = File.join(dir, 'POSTDEF') re1_path = File.join(dir, "123#{book.ext}") @@ -114,10 +115,10 @@ def test_read_postdef File.open(re1_path, 'w') { |o| o.print "123\n" } File.open(re2_path, 'w') { |o| o.print "456\n" } - assert_equal '', book.read_postdef + assert_equal [], book.read_postdef File.unlink(post_path) - assert_equal '', book.read_postdef + assert_equal [], book.read_postdef end end @@ -248,15 +249,15 @@ def test_parse_chpaters_with_parts_file '' ] ] - ].each do |n_parts, chaps_text, parts_text, part_names| + ].each do |n_parts, chaps, parts, part_names| n_test += 1 Dir.mktmpdir do |dir| book = Book::Base.new(dir) chaps_path = File.join(dir, 'CHAPS') - File.open(chaps_path, 'w') { |o| o.print chaps_text } - if parts_text + File.open(chaps_path, 'w') { |o| o.print chaps } + if parts parts_path = File.join(dir, 'PART') - File.open(parts_path, 'w') { |o| o.print parts_text } + File.open(parts_path, 'w') { |o| o.print parts } end parts = book.instance_eval { parse_chapters } diff --git a/test/test_catalog.rb b/test/test_catalog.rb index 98e277cf8..b27c4694f 100644 --- a/test/test_catalog.rb +++ b/test/test_catalog.rb @@ -7,61 +7,43 @@ class CatalogTest < Test::Unit::TestCase def test_predef sut = Catalog.new(yaml) - exp = <<-EOS -pre01.re -pre02.re - EOS - assert_equal(exp.chomp, sut.predef) + exp = %w[pre01.re pre02.re] + assert_equal(exp, sut.predef) end def test_chaps sut = Catalog.new(yaml) - exp = <<-EOS -ch01.re -ch02.re - EOS - assert_equal(exp.chomp, sut.chaps) + exp = %w[ch01.re ch02.re] + assert_equal(exp, sut.chaps) end def test_chaps_empty yaml = StringIO.new sut = Catalog.new(yaml) - assert_equal('', sut.chaps) + assert_equal([], sut.chaps) end def test_appendix sut = Catalog.new(yaml) - exp = <<-EOS -post01.re -post02.re - EOS - assert_equal(exp.chomp, sut.appendix) + exp = %w[post01.re post02.re] + assert_equal(exp, sut.appendix) end def test_chaps_with_parts sut = Catalog.new(yaml_with_parts) - exp = <<-EOS -ch01.re -ch02.re -ch03.re -ch04.re -ch05.re - EOS - assert_equal(exp.chomp, sut.chaps) + exp = %w[ch01.re ch02.re ch03.re ch04.re ch05.re] + assert_equal(exp, sut.chaps) end def test_parts sut = Catalog.new(yaml_with_parts) - exp = <<-EOS -part1.re -part2.re - EOS - assert_equal(exp.chomp, sut.parts) + exp = %w[part1.re part2.re] + assert_equal(exp, sut.parts) end def test_parts_with_empty sut = Catalog.new(yaml) - assert_equal('', sut.parts) + assert_equal([], sut.parts) end def test_empty_parts @@ -80,20 +62,14 @@ def test_parts2 def test_postdef sut = Catalog.new(yaml) - exp = <<-EOS -back01.re -back02.re - EOS - assert_equal(exp.chomp, sut.postdef) + exp = %w[back01.re back02.re] + assert_equal(exp, sut.postdef) end def test_from_object sut = Catalog.new(yaml_hash) - exp = <<-EOS -ch01.re -ch02.re - EOS - assert_equal(exp.chomp, sut.chaps) + exp = %w[ch01.re ch02.re] + assert_equal(exp, sut.chaps) end def test_validate