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

LATEXBuilder: fix //source #681

Merged
merged 1 commit into from
Nov 21, 2016
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
12 changes: 4 additions & 8 deletions lib/review/latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions templates/latex/layout.tex.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%>

Expand All @@ -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}}
Expand Down Expand Up @@ -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}}

Expand Down
7 changes: 7 additions & 0 deletions test/assets/test_template.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down Expand Up @@ -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}}

Expand Down
4 changes: 2 additions & 2 deletions test/test_latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down