Skip to content

Commit addf47f

Browse files
committed
add documentation
1 parent e4fd63e commit addf47f

File tree

4 files changed

+87
-2
lines changed

4 files changed

+87
-2
lines changed

doc/pdfmaker.ja.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,48 @@ Re:VIEW 3.0 から review-jlreq.cls という別のクラスファイルも用
109109

110110
その他の詳細な設定については、sty フォルダにある README.md を参照してください。
111111

112+
### カスタムパラメータの引き渡し
113+
114+
技術的な都合で、config.yml の YAML 設定から TeX のマクロへの変換はすべての設定について行われるわけではなく、ごく限られた値のみに制限しています。これは Re:VIEW 内部の `config.erb` ( https://github.com/kmuto/review/blob/master/templates/latex/config.erb ) の ERB スクリプトによって処理されており、この挙動を変更することは許容していません。
115+
116+
任意の YAML 設定を TeX に引き渡すには、`config.erb` と同様に YAML から TeX への変換を行う固有の ERB スクリプトを作成して配置します。このためには、プロジェクトフォルダに `layouts` フォルダを作成し、そこに固有の ERB スクリプトを `config-local.tex.erb` という名前で置きます。
117+
118+
`config-local.tex.erb``config.erb` の評価・埋め込みの後、評価・埋め込みされます。
119+
120+
config.yml を次のようにして、これを TeX に渡したいとします。
121+
122+
```
123+
mycustom:
124+
mystring: HELLO_#1
125+
mybool: true
126+
```
127+
128+
`layouts/config-local.tex.erb` はたとえば次のようになります。
129+
130+
```
131+
\def\mystring{<%= escape(@config['mycustom']['mystring']) %>}
132+
<%- if @config['mycustom']['mybool'] -%>
133+
\def\mybool{true}
134+
<%- end -%>
135+
```
136+
137+
次のように展開されます。
138+
```
139+
140+
\makeatother
141+
%% BEGIN: config-local.tex.erb
142+
\def\mystring{HELLO\textunderscore{}\#1}
143+
\def\mybool{true}
144+
%% END: config-local.tex.erb
145+
146+
\usepackage{reviewmacro}
147+
148+
```
149+
150+
こうして定義されたマクロを sty ファイルなどで参照します。
151+
152+
なお、ERB での YAML 解析、および TeX マクロの記述において誤りがあると、極めてわかりにくいエラーになることがあります。`--debug` オプション付きで実行して展開された `__REVIEW_BOOK__.tex` を確認して原因を調査するのがよいでしょう。
153+
112154
## Re:VIEW 2.0 以前の情報
113155

114156
### upLaTeX について

doc/pdfmaker.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,47 @@ Since Re:VIEW 3.0, review-jlreq.cls is also provided. This class file extends jl
8484

8585
`review-init --latex-template=review-jlreq` command copies the review-jlreq.cls set to `sty` folder.
8686

87+
### Handing over custom parameters
88+
89+
For technical reasons, only a small part of the YAML parameters in config.yml is converted to TeX macros. Re:VIEW's internal `config.erb` ( https://github.com/ kmuto/review/blob/master/templates/latex/ config.erb ) ERB script manages this. You cannot change this script.
90+
91+
If you want to give YAML parameters to TeX, you can use your own ERB script that do the YAML to TeX conversion. This is done by creating `layouts/config-local.tex.erb` in the project folder.
92+
93+
After evaluation and embedding of `config.erb`, `config-local.tex. erb` will be evaluated and embedded as well. For example,
94+
95+
`config.yml`:
96+
97+
```
98+
mycustom:
99+
mystring: HELLO_#1
100+
mybool: true
101+
```
102+
103+
`layouts/config-local.tex.erb`:
104+
105+
```
106+
\def\mystring{<%= escape(@config['mycustom']['mystring']) %>}
107+
<%- if @config['mycustom']['mybool'] -%>
108+
\def\mybool{true}
109+
<%- end -%>
110+
```
111+
112+
will be parsed:
113+
114+
```
115+
116+
\makeatother
117+
%% BEGIN: config-local.tex.erb
118+
\def\mystring{HELLO\textunderscore{}\#1}
119+
\def\mybool{true}
120+
%% END: config-local.tex.erb
121+
122+
\usepackage{reviewmacro}
123+
124+
```
125+
126+
Refer to these macros in your sty file.
127+
87128
## Important Changes about LaTeX in Re:VIEW 2.0
88129

89130
* Default LaTeX compiler is upLaTeX, not pLaTeX.

lib/review/pdfmaker.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,9 @@ def latex_config
477477
result = erb_content(File.expand_path('./latex/config.erb', ReVIEW::Template::TEMPLATE_DIR))
478478
local_config_file = File.join(@basedir, 'layouts', 'config-local.tex.erb')
479479
if File.exist?(local_config_file)
480+
result << "%% BEGIN: config-local.tex.erb\n"
480481
result << erb_content(local_config_file)
482+
result << "%% END: config-local.tex.erb\n"
481483
end
482484
result
483485
end

test/test_pdfmaker.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@ def test_template_content_with_localconfig
154154
Dir.mktmpdir do |dir|
155155
Dir.chdir(dir) do
156156
Dir.mkdir('layouts')
157-
File.write(File.join('layouts', 'config-local.tex.erb'), %q(\def\customvalue{<%= escape(@config['mycustom']['value']) %>}))
157+
File.write(File.join('layouts', 'config-local.tex.erb'), %q(\def\customvalue{<%= escape(@config['mycustom']['value']) %>}) + "\n")
158158
@maker.basedir = Dir.pwd
159159
@maker.erb_config
160160
tmpl = @maker.template_content
161161
expect = File.read(File.join(assets_dir, 'test_template.tex'))
162162
expect.gsub!(/\\def\\review@reviewversion{[^\}]+}/, "\\def\\review@reviewversion{#{ReVIEW::VERSION}}")
163-
expect.sub!("\\makeatother\n", '\&' + '\def\customvalue{\#\textunderscore{}TEST\textunderscore{}}')
163+
expect.sub!("\\makeatother\n", '\&' + "%% BEGIN: config-local.tex.erb\n\\def\\customvalue{\\#\\textunderscore{}TEST\\textunderscore{}}\n%% END: config-local.tex.erb\n")
164164
assert_equal(expect, tmpl)
165165
end
166166
end

0 commit comments

Comments
 (0)