From 294686e62bf393175ce43650b4e100229b2e0f80 Mon Sep 17 00:00:00 2001 From: srz_zumix Date: Tue, 16 Feb 2021 20:13:08 +0900 Subject: [PATCH] add ird sty (#11) * add ird sty * fix jsbook config * update for ird * update README --- Gemfile.lock | 2 +- README.md | 7 + lib/review/retrovert/converter.rb | 25 +- lib/review/retrovert/ext/review-ext.rb | 71 ++++++ lib/review/retrovert/sty/ird.sty | 318 +++++++++++++++++++++++++ lib/review/retrovert/version.rb | 2 +- spec/review/retrovert_spec.rb | 14 +- 7 files changed, 435 insertions(+), 4 deletions(-) create mode 100644 lib/review/retrovert/ext/review-ext.rb create mode 100644 lib/review/retrovert/sty/ird.sty diff --git a/Gemfile.lock b/Gemfile.lock index 1e3cd53..38ee9b3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - review-retrovert (0.9.6) + review-retrovert (0.9.7) review (>= 3.0.0) thor diff --git a/README.md b/README.md index e33d928..aaff01a 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,13 @@ inherit: ["config-base.yml", "config-starter.yml", "config-retrovert.yml"] #chapterlink: true ``` +## Experimental + +### IRD sty + +--ird オプションを付けると IRD 組版に近いレイアウトにするために ird.sty と reveiw-ext.rb をプロジェクトに追加します。 +こちらは実験的機能です。 + ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. diff --git a/lib/review/retrovert/converter.rb b/lib/review/retrovert/converter.rb index e333202..ad37c88 100644 --- a/lib/review/retrovert/converter.rb +++ b/lib/review/retrovert/converter.rb @@ -101,7 +101,13 @@ def update_config(outdir) @configs.rewrite_yml('hook_beforetexcompile', 'null') @configs.rewrite_yml('texstyle', '["reviewmacro"]') pagesize = @config['starter']['pagesize'].downcase - @configs.rewrite_yml_array('texdocumentclass', "[\"review-jsbook\", \"media=print,paper=#{pagesize}\"]") + jsbook_config = "media=print,paper=#{pagesize}" + if @ird + # # リュウミン Pr6N R-KL 12.5Q 22H (9pt = 12.7Q 15.5pt = 21.8Q(H)) + # texdocumentclass: ["review-jsbook", "media=ebook,openany,paper=b5,fontsize=9pt,baselineskip=15.5pt,head_space=15mm,gutter=22mm,footskip=16mm,line_length=45zw,number_of_lines=38"] + jsbook_config = "media=ebook,openany,paper=b5,fontsize=9pt,baselineskip=15.5pt,head_space=15mm,gutter=22mm,footskip=16mm,line_length=45zw,number_of_lines=38" + end + @configs.rewrite_yml_array('texdocumentclass', "[\"review-jsbook\", \"#{jsbook_config}\"]") @config['retrovert'].each{ |k,v| unless v..is_a?(Hash) @configs.commentout_root_yml(k) @@ -542,6 +548,21 @@ def preproc_contents(outdir, options) end end + def update_sty(outdir, options) + # FileUtils.cp(File.join(@basedir, 'sty/review-custom.sty'), File.join(outdir, 'sty/review-custom.sty')) + if @ird + FileUtils.cp(File.join(__dir__, 'sty/ird.sty'), File.join(outdir, 'sty/ird.sty')) + file = File.open(File.join(outdir, 'sty/review-custom.sty'), 'a') + file.puts('\RequirePackage{ird}') + end + end + + def update_ext(outdir, options) + if @ird + FileUtils.cp(File.join(__dir__, 'ext/review-ext.rb'), File.join(outdir, 'review-ext.rb')) + end + end + def clean_initial_project(outdir) FileUtils.rm(File.join(outdir, 'config.yml')) FileUtils.rm(File.join(outdir, 'catalog.yml')) @@ -586,6 +607,8 @@ def execute(yamlfile, outdir, options) copy_images(outdir, store_image_dir) update_config(outdir) update_contents(outdir, options) + update_sty(outdir, options) + update_ext(outdir, options) pwd = Dir.pwd Dir.chdir(outdir) diff --git a/lib/review/retrovert/ext/review-ext.rb b/lib/review/retrovert/ext/review-ext.rb new file mode 100644 index 0000000..8ca87fe --- /dev/null +++ b/lib/review/retrovert/ext/review-ext.rb @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- + +## +## ReVIEW::LATEXBuilderクラスを拡張する +## + +require 'review/latexbuilder' + + +module ReVIEW + + defined?(LATEXBuilder) or raise "internal error: LATEXBuilder not found." + + + module LATEXBuilderForIRD + # def headline(level, label, caption) + # if level >= 4 + # puts '\needspace{3zh}' + # end + # super(level,label,caption) + # puts '\nopagebreak[4]' + # end + + def ul_begin + blank + puts '\begin{reviewitemize}' + end + def ul_end + puts '\end{reviewitemize}' + blank + end + end + + class LATEXBuilder + prepend LATEXBuilderForIRD + + # def headline(level, label, caption) + # _, anchor = headline_prefix(level) + # headline_name = HEADLINE[level] + # if @chapter.is_a?(ReVIEW::Book::Part) + # if @book.config.check_version('2', exception: false) + # headline_name = 'part' + # elsif level == 1 + # headline_name = 'part' + # puts '\begin{reviewpart}' + # end + # end + # prefix = '' + # if level > @book.config['secnolevel'] || (@chapter.number.to_s.empty? && level > 1) + # prefix = '*' + # end + # blank unless @output.pos == 0 + # @doc_status[:caption] = true + # puts macro(headline_name + prefix, compile_inline(caption)) + # puts '\nopagebreak[4]' + # @doc_status[:caption] = nil + # if prefix == '*' && level <= @book.config['toclevel'].to_i + # puts "\\addcontentsline{toc}{#{headline_name}}{#{compile_inline(caption)}}" + # end + # if level == 1 + # puts macro('label', chapter_label) + # else + # puts macro('label', sec_label(anchor)) + # puts macro('label', label) if label + # end + # puts '\nopagebreak[4]' + # rescue + # error "unknown level: #{level}" + # end + end +end diff --git a/lib/review/retrovert/sty/ird.sty b/lib/review/retrovert/sty/ird.sty new file mode 100644 index 0000000..bb464d4 --- /dev/null +++ b/lib/review/retrovert/sty/ird.sty @@ -0,0 +1,318 @@ +% +% フォント +% + +% \tiny 5pt +% \scriptsize 7pt +% \footnotesize 8pt +% \small 9pt +% \normalsize 10pt(標準) +% \large 12pt +% \Large 14.4pt +% \LARGE 17.28pt +% \huge 20.74pt +% \Huge + +\def\@setfontsize#1#2#3{% + \ifx\protect\@typeset@protect + \let\@currsize#1% + \fi + \fontsize{#2}{#3}\selectfont + \ifdim\parindent>\z@ + \if@english + \parindent=1em + \else + \parindent=1zw + \fi + \fi + \kanjiskip=0zw plus .1zw minus .01zw + \ifdim\xkanjiskip>\z@ + \if@slide \xkanjiskip=0.1em \else + % \xkanjiskip=0.25em plus 0.15em minus 0.06em + \xkanjiskip=0.2em plus 0.15em minus 0.16em + \fi + \fi +} + +% +% 章・節・項の変更 +% + +\def\@afterheading{% + \@nobreaktrue + \everypar{% + \if@nobreak + \@nobreakfalse + % \clubpenalty \@M + \clubpenalty \z@ % 段落一段目での改ページを許可する + \if@afterindent \else + {\setbox\z@\lastbox}% + \fi + \else + \clubpenalty \@clubpenalty + \everypar{\everyparhook}% + \fi\everyparhook}} + + +\def\@makechapterhead#1{% +% \vspace*{2\Cvs}% 欧文は50pt →上空きを無効化 + {\parindent \z@ \raggedright \normalfont + \ifnum \c@secnumdepth >\m@ne + \if@mainmatter + \huge\headfont \@chapapp\thechapter\@chappos + % \par\nobreak + % \vskip \Cvs % 欧文は20pt + \fi + \fi + \interlinepenalty\@M + \huge \headfont \ #1\par\nobreak + \vskip 3\Cvs}} % 欧文は40pt + +% \usepackage[hiragino-pron]{pxchfon} +\renewcommand{\headfont}{\gtfamily\sffamily} + +% \hyphenpenalty=10000\relax + +\renewcommand{\section}{% + \if@slide\clearpage\fi + \@startsection{section}{1}{\z@}% + {1.3\Cvs \@plus.5\Cdp \@minus1.2\Cdp}% 前アキ + {.5\Cvs \@plus.3\Cdp}% 後アキ + {\normalfont\large\bfseries\headfont\raggedright}} + +\renewcommand{\subsection}{\@startsection{subsection}{2}{\z@}% + {.8\Cvs \@plus.5\Cdp \@minus1.2\Cdp}% 前アキ + {.5\Cvs \@plus.3\Cdp}% 後アキ + {\normalfont\normalsize\headfont}} + +\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{\z@}% + {.6\Cvs \@plus.5\Cdp \@minus1.2\Cdp}% + {\if@slide .2\Cvs \@plus.6\Cdp \else .2\Cvs \@plus.3\Cdp \fi}% + {\normalfont\normalsize}} + +\def\@startsection#1#2#3#4#5#6{% + \if@noskipsec \leavevmode \fi + \par + \@tempskipa #4\relax + \if@english \@afterindentfalse \else \@afterindenttrue \fi + \ifdim \@tempskipa <\z@ + \@tempskipa -\@tempskipa \@afterindentfalse + \fi + \if@nobreak + \everypar{}% + \else + \addpenalty\@secpenalty\addvspace\@tempskipa + %改ページ後の不要な空白を削除 +% \addpenalty\@secpenalty +% \ifdim \@tempskipa >\z@ +% \if@slide +% \else +% \null +% \vspace*{-\baselineskip}% +% \fi +% \vskip\@tempskipa +% \fi + \fi + \noindent + \@ifstar + {\@ssect{#3}{#4}{#5}{#6}}% + {\@dblarg{\@sect{#1}{#2}{#3}{#4}{#5}{#6}}}} + +% \def\@ssect#1#2#3#4#5{% +% \@tempskipa #3\relax +% \ifdim \@tempskipa<\z@ +% \def\@svsechd{#4{\hskip #1\relax #5}}% +% \else +% \begingroup +% #4{% +% \@hangfrom{\hskip #1}% +% \interlinepenalty \@M #5\@@par}% +% \endgroup +% \nopagebreak[4]% +% \fi +% \@xsect{#3}} + +% \def\@xsect#1{% +% \@tempskipa #1\relax +% \ifdim \@tempskipa<\z@ +% \@nobreakfalse +% \global\@noskipsectrue +% \everypar{% +% \if@noskipsec +% \global\@noskipsecfalse +% {\setbox\z@\lastbox}% +% \clubpenalty\@M +% \begingroup \@svsechd \endgroup +% \unskip +% \@tempskipa #1\relax +% \hskip -\@tempskipa +% \else +% \clubpenalty \@clubpenalty +% \everypar{\everyparhook}% +% \fi\everyparhook}% +% \else +% \nopagebreak[4] +% \par \nobreak +% \vskip \@tempskipa +% \@afterheading +% \fi +% \if@slide +% {\vskip\if@twocolumn-5\jsc@mpt\else-6\jsc@mpt\fi +% \maybeblue\hrule height0\jsc@mpt depth1\jsc@mpt +% \vskip\if@twocolumn 4\jsc@mpt\else 7\jsc@mpt\fi\relax}% +% \fi +% \par % 2000-12-18 +% \ignorespaces} + +% +% コラムの変更 +% + +\def\ifempty#1{\def\temp{#1} \ifx\temp\empty } + +\renewenvironment{reviewcolumn}[1][]{% + \begin{framed} + \ifempty{#1}% + \else% + \reviewcolumnhead{}{#1}% + \fi% + \footnotesize + }{% + \end{framed} + % \vspace{-2pt} + } + +\renewcommand{\reviewcolumnhead}[2]{% + {\noindent\large\bfseries #2}\vspace{1.7mm}} + + +% +% 図 +% + +\renewenvironment{reviewimage}{% + \begin{figure} + \begin{flushleft}}{% + \end{flushleft} + \end{figure} + \vspace{-5.5pt} + } + +% \renewcommand\reviewimagecaption[1]{% +% \captionsetup{format=hang,font=scriptsize,labelfont=bf,margin=50pt,name=図} +% \caption{ \bfseries\scriptsize{#1}} \vspace{-1.5mm}} + +\renewcommand\reviewimagecaption[1]{% + \captionsetup{format=hang,font=footnotesize,labelfont=bf,margin=0pt,justification=raggedright,singlelinecheck=off,name=図} + \vspace{-1mm} \caption{ \bfseries\footnotesize{#1} } \vspace{-1.5mm}} + +% % フォントのに対して調整 +% \def\irdmaxwidth{0.99\textwidth} +% \usepackage[export]{adjustbox} +% \DeclareRobustCommand{\reviewincludegraphics}[2][]{% +% \adjustbox{max width=\irdmaxwidth}{% +% \includegraphics[#1]{#2}}% +% } + +% +% 表 +% +\renewcommand{\reviewtablecaption}[1]{% + \captionsetup{format=hang,font=footnotesize,margin=70pt,name=表} + \caption{ \footnotesize{#1}} \vspace{-3mm}} + +\renewcommand{\reviewimgtablecaption}[1]{% + \captionsetup{format=hang,font=footnotesize,margin=70pt,name=表} + \caption{ \footnotesize\noindent{#1}} \vspace{-3mm}} + +% +% 箇条書き +% + +% \usepackage{enumitem} +% \setlist[enumerate]{topsep=0pt,parsep=1pt} +% \setlist[itemize]{topsep=0pt,parsep=1pt} + +\newenvironment{reviewitemize}{% + \ifnum\@listdepth=0% + \def\@listi{% + \@listI% + % \topsep 0.1\baselineskip% % 上下の余白を減らす(original: 0.5\baselineskip) + % \topsep \z@% % 上下の余白を減らす(original: 0.5\baselineskip) + \topsep -0.25\baselineskip% % 上下の余白を減らす(original: 0.5\baselineskip) + }% + \fi% + \begin{itemize}% + \setlength{\parskip}{-0.6pt}% 要素の間隔を詰める +}{% + \end{itemize}% +} + +% +% リスト +% + +\renewcommand{\reviewlistcaption}[1]{% +\vspace*{0.6zw}\medskip{\small\noindent #1}\vspace*{-1.3zw}} + +\renewenvironment{reviewlist}{% + \begin{shaded}% + \vspace*{-1zw}% 前後の余白削除 + \small% + \ifdefined\reviewlistxkanjiskip% + \xkanjiskip=\reviewlistxkanjiskip% + \fi% + \setlength{\baselineskip}{1.3zw}% + \begin{alltt}}{% + \end{alltt}% + \vspace*{-1zw}% 前後の余白削除 + \end{shaded}% + \par% + % \vspace*{0.5zw}% + \vspace*{1zw}% + } + +% +% cmd +% + +\renewenvironment{reviewlistblock}{\needspace{\Cvs}}{} + +\renewenvironment{reviewcmd}{% + \medskip% + \ifdefined\reviewlistxkanjiskip% + \xkanjiskip=\reviewlistxkanjiskip% + \fi% + \vspace*{-2.5zw \@plus.3\Cdp}% 枠の前の余白削除 + \begin{framed}% + % \interlinepenalty=10000% + \vspace*{-0.8zw}% 前後の余白削除 + % \setlength{\baselineskip}{1.3zw}% + \setlength{\baselineskip}{2zw}% + \begin{alltt}}{% + \end{alltt}% + \vspace*{-0.8zw}% 前後の余白削除 + \end{framed}% + \vspace*{0.3mm}% 枠の後ろの余白の調整 + } + +% \renewenvironment{reviewcmd}{% +% \medskip% +% \ifdefined\reviewlistxkanjiskip% +% \xkanjiskip=\reviewlistxkanjiskip% +% \fi% +% \vspace*{-2zw \@plus2.7\Cdp}% 枠の前の余白削除 +% \begin{framed}% +% \vspace*{-1zw}% 前後の余白削除 +% % \setlength{\baselineskip}{1.3zw}% +% \setlength{\baselineskip}{2zw}% +% \begin{alltt}}{% +% \end{alltt}% +% \vspace*{-1zw}% 前後の余白削除 +% \end{framed}% +% % この値だといい感じになる +% \vspace*{-0.2mm}% 枠の後ろの余白の調整 +% } + + % code +\DeclareRobustCommand{\reviewcode}[1]{{\small\ttfamily\reviewbreakall{#1}}} diff --git a/lib/review/retrovert/version.rb b/lib/review/retrovert/version.rb index a8c223c..63afe4e 100644 --- a/lib/review/retrovert/version.rb +++ b/lib/review/retrovert/version.rb @@ -1,5 +1,5 @@ module ReVIEW module Retrovert - VERSION = "0.9.6" + VERSION = "0.9.7" end end diff --git a/spec/review/retrovert_spec.rb b/spec/review/retrovert_spec.rb index 7373c22..256de37 100644 --- a/spec/review/retrovert_spec.rb +++ b/spec/review/retrovert_spec.rb @@ -30,6 +30,7 @@ let(:inner) { 'tmp/contents/r0-inner.re' } let(:config) { 'tmp/config.yml' } let(:retrovert_config) { 'tmp/config-retrovert.yml' } + let(:custom_sty) { 'tmp/sty/review-custom.sty' } before(:each) { run_command("review-retrovert convert --preproc --tabwidth 4 --ird #{config_yaml} tmp") } it 'command result' do @@ -267,8 +268,19 @@ expect(root).to be_an_existing_file text = File.open(File.join(aruba.current_directory, root)).read() expect(text).not_to match(/^\s*@
{}\s*$/) - expect(text).to match(/^\s*.*@
{}\s*$/) + # expect(text).to match(/^\s*.*@
{}\s*$/) expect(text).to match(/^\/\/blankline$/) end + + it 'sty' do + expect('tmp/sty/ird.sty').to be_an_existing_file + expect(custom_sty).to be_an_existing_file + text = File.open(File.join(aruba.current_directory, custom_sty)).read() + expect(text).to include('\RequirePackage{ird}') + end + + it 'ext' do + expect('tmp/review-ext.rb').to be_an_existing_file + end end end