From 56465490f33535decbeb65ffac678d248c4660fd Mon Sep 17 00:00:00 2001 From: takahashim Date: Sun, 20 Nov 2016 18:30:13 +0900 Subject: [PATCH] LATEXBuilder: fix //source add new macro `reviewsource` and `reviewsourcecaption` for `//source` command. cf. #651 --- lib/review/latexbuilder.rb | 12 ++++-------- templates/latex/layout.tex.erb | 9 +++++++++ test/assets/test_template.tex | 7 +++++++ test/test_latexbuilder.rb | 4 ++-- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/review/latexbuilder.rb b/lib/review/latexbuilder.rb index 09b2db90b..52f087aaa 100644 --- a/lib/review/latexbuilder.rb +++ b/lib/review/latexbuilder.rb @@ -305,7 +305,7 @@ def cmd(lines, caption = nil, lang = nil) def common_code_block(id, lines, command, caption, lang) if caption - if command =~ /emlist/ || command =~ /cmd/ + if command =~ /emlist/ || command =~ /cmd/ || command =~ /source/ puts macro(command + 'caption', "#{compile_inline(caption)}") else begin @@ -346,15 +346,11 @@ def common_code_block_lst(id, lines, command, title, caption, lang) def source(lines, caption, lang = nil) if highlight_listings? - common_code_block_lst(nil, lines, 'reviewlistlst', 'title', caption, lang) + common_code_block_lst(nil, lines, 'reviewsourcelst', 'title', caption, lang) else - puts '\begin{reviewlist}' - puts macro('reviewlistcaption', compile_inline(caption)) - lines.each do |line| - puts detab(line) + common_code_block(nil, lines, 'reviewsource', caption, lang) do |line, idx| + detab(line) + "\n" end - puts '\end{reviewlist}' - puts "" end end diff --git a/templates/latex/layout.tex.erb b/templates/latex/layout.tex.erb index 89078b2d6..2a8a86287 100644 --- a/templates/latex/layout.tex.erb +++ b/templates/latex/layout.tex.erb @@ -79,6 +79,8 @@ \lstnewenvironment{reviewemlistnumlst}[1][]{\lstset{numbers=left, #1}}{} \lstnewenvironment{reviewlistlst}[1][]{\lstset{#1}}{} \lstnewenvironment{reviewlistnumlst}[1][]{\lstset{numbers=left, #1}}{} +\lstnewenvironment{reviewsourcelst}[1][]{\lstset{#1}}{} +\lstnewenvironment{reviewsourcenumlst}[1][]{\lstset{numbers=left, #1}}{} \lstnewenvironment{reviewcmdlst}[1][]{\lstset{backgroundcolor=\color{white}, frameround=tttt, frame=trbl, #1}}{} <%- end -%> @@ -102,6 +104,10 @@ \begin{shaded}\small\setlength{\baselineskip}{1.3zw}\begin{alltt}}{% \end{alltt}\end{shaded}\par\vspace*{0.5zw}} +\newenvironment{reviewsource}{% + \begin{shaded}\small\setlength{\baselineskip}{1.3zw}\begin{alltt}}{% + \end{alltt}\end{shaded}\par\vspace*{0.5zw}} + \newenvironment{reviewcmd}{% \color{white}\medskip\small\begin{shadedb}\setlength{\baselineskip}{1.3zw}\begin{alltt}}{% \end{alltt}\end{shadedb}} @@ -140,6 +146,9 @@ \newcommand{\reviewemlistcaption}[1]{% \medskip{\small\noindent #1}\vspace*{-1.3zw}} +\newcommand{\reviewsourcecaption}[1]{% + \medskip{\small\noindent #1}\vspace*{-1.3zw}} + \newcommand{\reviewcmdcaption}[1]{% \medskip{\small\noindent #1}\vspace*{-1.3zw}} diff --git a/test/assets/test_template.tex b/test/assets/test_template.tex index 1cca834e5..8124599c5 100644 --- a/test/assets/test_template.tex +++ b/test/assets/test_template.tex @@ -64,6 +64,10 @@ \begin{shaded}\small\setlength{\baselineskip}{1.3zw}\begin{alltt}}{% \end{alltt}\end{shaded}\par\vspace*{0.5zw}} +\newenvironment{reviewsource}{% + \begin{shaded}\small\setlength{\baselineskip}{1.3zw}\begin{alltt}}{% + \end{alltt}\end{shaded}\par\vspace*{0.5zw}} + \newenvironment{reviewcmd}{% \color{white}\medskip\small\begin{shadedb}\setlength{\baselineskip}{1.3zw}\begin{alltt}}{% \end{alltt}\end{shadedb}} @@ -102,6 +106,9 @@ \newcommand{\reviewemlistcaption}[1]{% \medskip{\small\noindent #1}\vspace*{-1.3zw}} +\newcommand{\reviewsourcecaption}[1]{% + \medskip{\small\noindent #1}\vspace*{-1.3zw}} + \newcommand{\reviewcmdcaption}[1]{% \medskip{\small\noindent #1}\vspace*{-1.3zw}} diff --git a/test/test_latexbuilder.rb b/test/test_latexbuilder.rb index 1025a0527..bb8c6e094 100644 --- a/test/test_latexbuilder.rb +++ b/test/test_latexbuilder.rb @@ -320,14 +320,14 @@ def test_listnum_lst def test_source actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n") - assert_equal %Q|\\begin{reviewlist}\n\\reviewlistcaption{foo/bar/test.rb}\nfoo\nbar\n\nbuz\n\\end{reviewlist}\n\n|, actual + assert_equal %Q|\\reviewsourcecaption{foo/bar/test.rb}\n\\begin{reviewsource}\nfoo\nbar\n\nbuz\n\\end{reviewsource}\n|, actual end def test_source_lst @book.config["highlight"] = {} @book.config["highlight"]["latex"] = "listings" actual = compile_block("//source[foo/bar/test.rb]{\nfoo\nbar\n\nbuz\n//}\n") - assert_equal %Q|\\begin{reviewlistlst}[title={foo/bar/test.rb},language={}]\nfoo\nbar\n\nbuz\n\\end{reviewlistlst}\n|, actual + assert_equal %Q|\\begin{reviewsourcelst}[title={foo/bar/test.rb},language={}]\nfoo\nbar\n\nbuz\n\\end{reviewsourcelst}\n|, actual end def test_quote