Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

review-initで明示的にtexdocumentclassを設定 #1202

Merged
merged 4 commits into from
Nov 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/config.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ epubmaker:
# texstyle: ["reviewmacro"]
#
# LaTeX用のdocumentclassを指定する
# review-jsbook.clsのオプションについてはsty/README.mdを参照
# オプションについてはsty/README.mdを参照
# デフォルトは印刷用。電子配布版を作るには media=ebook とする
# texdocumentclass: ["review-jsbook", "media=print,paper=a5"]
#
# LaTeX用のコマンドを指定する
Expand Down
10 changes: 10 additions & 0 deletions lib/review/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ def self.execute(*args)
new.execute(*args)
end

TEX_DOCUMENTCLASS_OPTS = {
'review-jsbook' => 'media=print,paper=a5',
'review-jlreq' => 'media=print,paper=a5'
}

def initialize
@template = 'review-jsbook'
@logger = ReVIEW.logger
Expand Down Expand Up @@ -148,6 +153,11 @@ def generate_config(dir)
content.gsub!(/^#.*epubversion:.*$/, 'epubversion: 2')
content.gsub!(/^#.*htmlversion:.*$/, 'htmlversion: 4')
end

if TEX_DOCUMENTCLASS_OPTS[@template]
content.gsub!(/^#\s*texdocumentclass:.*$/, %Q(texdocumentclass: ["#{@template}", "#{TEX_DOCUMENTCLASS_OPTS[@template]}"]))
end

File.open(File.join(dir, 'config.yml'), 'w') { |f| f.write(content) }
end

Expand Down
50 changes: 35 additions & 15 deletions lib/review/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ def update_tex_parameters
@template = nil
else
@template = config['texdocumentclass'][0]

if @template == 'review-jsbook'
update_review_jsbook_opts(yml, config['texdocumentclass'][1])
end
end

# no need to update
Expand Down Expand Up @@ -365,23 +369,41 @@ def update_tex_parameters
end

flag, modified_opts = convert_documentclass_opts(yml, @template, config['texdocumentclass'][1])
if flag # successfully converted
@logger.info t("%s: previous 'texdocumentclass' option '%s' is safely replaced with '%s'.", [File.basename(yml), config['texdocumentclass'][1], modified_opts])
else # something wrong
unless confirm("%s: previous 'texdocumentclass' option '%s' couldn't be converted fully. '%s' is suggested. Do you really proceed?", [File.basename(yml), config['texdocumentclass'][1], modified_opts], nil)
@template = nil
next
end
end

rewrite_yml(yml, 'texdocumentclass', %Q(["#{@template}", "#{modified_opts}"]))
rewrite_documentclass_opts_by_flag(flag, yml, config['texdocumentclass'][1], modified_opts)
else
@template = nil
@logger.error t("%s: ** 'texdocumentclass' specifies '%s'. Because this is unknown class for this tool, you need to update it by yourself if it won't work. **", [File.basename(yml), config['texdocumentclass'][0]])
end
end
end

def rewrite_documentclass_opts_by_flag(flag, yml, old_opts, modified_opts)
if flag # successfully converted
@logger.info t("%s: previous 'texdocumentclass' option '%s' is safely replaced with '%s'.", [File.basename(yml), old_opts, modified_opts])
else # something wrong
unless confirm("%s: previous 'texdocumentclass' option '%s' couldn't be converted fully. '%s' is suggested. Do you really proceed?", [File.basename(yml), old_opts, modified_opts], nil)
@template = nil
return nil
end
end

rewrite_yml(yml, 'texdocumentclass', %Q(["#{@template}", "#{modified_opts}"]))
end

def update_review_jsbook_opts(yml, old_opts)
modified_opts = old_opts.gsub(/Q=([^,]+)/, 'fontsize=\1Q').
gsub(/W=([^,]+)/, 'line_length=\1zw').
gsub(/L=([^,]+)/, 'number_of_lines=\1').
gsub(/H=([^,]+)/, 'baselineskip=\1H').
gsub(/head=([^,]+)/, 'head_space=\1')

if modified_opts == old_opts
return nil
end

rewrite_documentclass_opts_by_flag(true, yml, old_opts, modified_opts)
end

def convert_documentclass_opts(yml, cls, prev_opts)
# XXX: at this time, review-jsbook and review-jlreq uses same parameters
opts = []
Expand All @@ -393,13 +415,11 @@ def convert_documentclass_opts(yml, cls, prev_opts)
when 'a4j', 'a5j', 'b4j', 'b5j', 'a3paper', 'a4paper', 'a5paper', 'a6paper', 'b4paper', 'b5paper', 'b6paper', 'letterpaper', 'legalpaper', 'executivepaper'
opts << "paper=#{v.sub('j', '').sub('paper', '')}"
when /[\d.]+ptj/ # not cared...
q = sprintf('%.2f', v.sub('pt', '').to_f * 1.4056)
opts << "Q=#{q}"
opts << "fontsize=#{v.sub('j', '')}"
when /[\d.]+pt/
q = sprintf('%.2f', v.sub('pt', '').to_f * 1.4056)
opts << "Q=#{q}"
opts << "fontsize=#{v}"
when /[\d.]+Q/
opts << "Q=#{v.sub('Q', '')}"
opts << "fontsize=#{v}"
when 'landscape', 'oneside', 'twoside', 'vartwoside', 'onecolumn',
'twocolumn', 'titlepage', 'notitlepage', 'openright',
'openany', 'leqno', 'fleqn', 'disablejfam', 'draft', 'final',
Expand Down
Loading