Skip to content

Commit

Permalink
Merge pull request #1040 from kmuto/fix-listings-caption
Browse files Browse the repository at this point in the history
LATEXBuilder: fix empty caption for listings
  • Loading branch information
takahashim authored Jun 19, 2018
2 parents 532bd61 + 2d622cb commit 93f7d86
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
15 changes: 7 additions & 8 deletions lib/review/latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,6 @@ def common_code_block(id, lines, command, caption, _lang)
end

def common_code_block_lst(_id, lines, command, title, caption, lang, first_line_num: 1)
if title == 'title' && caption.blank?
print '\vspace{-1.5em}'
end
body = lines.inject('') { |i, j| i + detab(unescape(j)) + "\n" }
args = make_code_block_args(title, caption, lang, first_line_num: first_line_num)
puts %Q(\\begin{#{command}}[#{args}])
Expand All @@ -375,18 +372,20 @@ def common_code_block_lst(_id, lines, command, title, caption, lang, first_line_

def make_code_block_args(title, caption, lang, first_line_num: 1)
caption_str = compile_inline((caption || ''))
if title == 'title' && caption_str == ''
caption_str = '\relax' ## dummy charactor to remove lstname
end
lexer = if @book.config['highlight'] && @book.config['highlight']['lang']
@book.config['highlight']['lang'] # default setting
else
''
end
lexer = lang if lang.present?
args = %Q(#{title}={#{caption_str}},language={#{lexer}})
args = "language={#{lexer}}"
if title == 'title' && caption_str == ''
# ignore
else
args = "#{title}={#{caption_str}}," + args
end
if first_line_num != 1
args += ",firstnumber=#{first_line_num}"
args << ",firstnumber=#{first_line_num}"
end
args
end
Expand Down
6 changes: 3 additions & 3 deletions test/test_latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def test_cmd_lst
@book.config['highlight'] = {}
@book.config['highlight']['latex'] = 'listings'
actual = compile_block("//cmd{\nfoo\nbar\n\nbuz\n//}\n")
assert_equal %Q(\\vspace{-1.5em}\\begin{reviewcmdlst}[title={\\relax},language={}]\nfoo\nbar\n\nbuz\n\\end{reviewcmdlst}\n), actual
assert_equal %Q(\\begin{reviewcmdlst}[language={}]\nfoo\nbar\n\nbuz\n\\end{reviewcmdlst}\n), actual
end

def test_emlist
Expand All @@ -314,15 +314,15 @@ def test_emlist_lst
@book.config['highlight'] = {}
@book.config['highlight']['latex'] = 'listings'
actual = compile_block("//emlist[][sql]{\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n//}\n")
assert_equal %Q(\n\\vspace{-1.5em}\\begin{reviewemlistlst}[title={\\relax},language={sql}]\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n\\end{reviewemlistlst}\n), actual
assert_equal %Q(\n\\begin{reviewemlistlst}[language={sql}]\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n\\end{reviewemlistlst}\n), actual
end

def test_emlist_lst_without_lang
@book.config['highlight'] = {}
@book.config['highlight']['latex'] = 'listings'
@book.config['highlight']['lang'] = 'sql'
actual = compile_block("//emlist[]{\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n//}\n")
assert_equal %Q(\n\\vspace{-1.5em}\\begin{reviewemlistlst}[title={\\relax},language={sql}]\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n\\end{reviewemlistlst}\n), actual
assert_equal %Q(\n\\begin{reviewemlistlst}[language={sql}]\nSELECT COUNT(*) FROM tests WHERE tests.no > 10 AND test.name LIKE 'ABC%'\n\\end{reviewemlistlst}\n), actual
end

def test_emlist_caption
Expand Down

0 comments on commit 93f7d86

Please sign in to comment.