Skip to content

Commit

Permalink
LATEXBuilder: fix to use keywords in locale.yml (#629)
Browse files Browse the repository at this point in the history
  • Loading branch information
takahashim committed May 6, 2016
1 parent 1ced03f commit daa3b5e
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
11 changes: 11 additions & 0 deletions lib/review/pdfmaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,17 @@ def get_template
@coverimageoption = "width=\\textwidth,height=\\textheight,keepaspectratio"
end

@locale_latex = Hash.new
part_tuple = I18n.get("part").split(/\%[A-Za-z]{1,3}/, 2)
chapter_tuple = I18n.get("chapter").split(/\%[A-Za-z]{1,3}/, 2)
appendix_tuple = I18n.get("appendix").split(/\%[A-Za-z]{1,3}/, 2)
@locale_latex["prepartname"] = part_tuple[0]
@locale_latex["postpartname"] = part_tuple[1]
@locale_latex["prechaptername"] = chapter_tuple[0]
@locale_latex["postchaptername"] = chapter_tuple[1]
@locale_latex["preappendixname"] = appendix_tuple[0]
@locale_latex["postappendixname"] = appendix_tuple[1]

template = File.expand_path('./latex/layout.tex.erb', ReVIEW::Template::TEMPLATE_DIR)
layout_file = File.join(@basedir, "layouts", "layout.tex.erb")
if File.exist?(layout_file)
Expand Down
35 changes: 34 additions & 1 deletion templates/latex/layout.tex.erb
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@
{\large <%= I18n.t("memo_head")%>: #1}\\}

<%- if @config["toctitle"].present? -%>
\renewcommand{\contentsname}{<%= @config["toctitle"]%>}
\renewcommand{\contentsname}{<%= escape_latex(@config["toctitle"]) %>}
<%- elsif I18n.t("toctitle") -%>
\renewcommand{\contentsname}{<%= escape_latex(I18n.t("toctitle")) %>}
<%- end -%>

\newenvironment{reviewminicolumn}{%
Expand Down Expand Up @@ -199,6 +201,37 @@
\newcommand{\reviewcolophon}[0]{\clearpage}
\newcommand{\reviewappendix}[0]{\appendix}

\newcommand{\reviewprepartname}{<%= escape_latex(@locale_latex["prepartname"]) %>}
\newcommand{\reviewpostpartname}{<%= escape_latex(@locale_latex["postpartname"]) %>}
\newcommand{\reviewprechaptername}{<%= escape_latex(@locale_latex["prechaptername"]) %>}
\newcommand{\reviewpostchaptername}{<%= escape_latex(@locale_latex["postchaptername"]) %>}
\newcommand{\reviewfigurename}{<%= escape_latex(I18n.t("image")) %>}
\newcommand{\reviewtablename}{<%= escape_latex(I18n.t("table")) %>}
\newcommand{\reviewappendixname}{<%= escape_latex(@locale_latex["preappendixname"]) %>}

\ifdefined\prepartname
\renewcommand{\prepartname}{\reviewprepartname}
\fi
\ifdefined\postpartname
\renewcommand{\postpartname}{\reviewpostpartname}
\fi
\ifdefined\prechaptername
\renewcommand{\prechaptername}{\reviewprechaptername}
\fi
\ifdefined\postchaptername
\renewcommand{\postchaptername}{\reviewpostchaptername}
\fi
\ifdefined\figurename
\renewcommand{\figurename}{\reviewfigurename}
\fi
\ifdefined\tablename
\renewcommand{\tablename}{\reviewtablename}
\fi
\ifdefined\appendixname
\renewcommand{\appendixname}{\reviewappendixname}
\fi


\makeatletter
%% maxwidth is the original width if it is less than linewidth
%% otherwise use linewidth (to make sure the graphics do not exceed the margin)
Expand Down
32 changes: 32 additions & 0 deletions test/assets/test_template.tex
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
\newcommand{\reviewminicolumntitle}[1]{%
{\large ■メモ: #1}\\}

\renewcommand{\contentsname}{目次}

\newenvironment{reviewminicolumn}{%
\vspace{1.5zw}\begin{screen}}{%
Expand All @@ -141,6 +142,37 @@
\newcommand{\reviewcolophon}[0]{\clearpage}
\newcommand{\reviewappendix}[0]{\appendix}

\newcommand{\reviewprepartname}{第}
\newcommand{\reviewpostpartname}{部}
\newcommand{\reviewprechaptername}{第}
\newcommand{\reviewpostchaptername}{章}
\newcommand{\reviewfigurename}{図}
\newcommand{\reviewtablename}{表}
\newcommand{\reviewappendixname}{付録}

\ifdefined\prepartname
\renewcommand{\prepartname}{\reviewprepartname}
\fi
\ifdefined\postpartname
\renewcommand{\postpartname}{\reviewpostpartname}
\fi
\ifdefined\prechaptername
\renewcommand{\prechaptername}{\reviewprechaptername}
\fi
\ifdefined\postchaptername
\renewcommand{\postchaptername}{\reviewpostchaptername}
\fi
\ifdefined\figurename
\renewcommand{\figurename}{\reviewfigurename}
\fi
\ifdefined\tablename
\renewcommand{\tablename}{\reviewtablename}
\fi
\ifdefined\appendixname
\renewcommand{\appendixname}{\reviewappendixname}
\fi


\makeatletter
%% maxwidth is the original width if it is less than linewidth
%% otherwise use linewidth (to make sure the graphics do not exceed the margin)
Expand Down
1 change: 1 addition & 0 deletions test/test_pdfmaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def setup
"texcommand" => "uplatex",
})
@maker.config = @config
@maker.initialize_metachars(@config["texcommand"])
@output = StringIO.new
I18n.setup(@config["language"])
end
Expand Down

0 comments on commit daa3b5e

Please sign in to comment.