Skip to content

Commit 4d05855

Browse files
committed
Fixing up gobbling of lines after DEFMACRO and adding test case.
1 parent 3c87aa1 commit 4d05855

3 files changed

Lines changed: 34 additions & 11 deletions

File tree

src/latex.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -486,30 +486,29 @@ void SpLatex::defmacro(size_t ln, size_t indent, const std::string& cmdline)
486486
{
487487
for (unsigned int col = 0; col < count; ++col) {
488488
if (col != 0) oss << std::endl;
489-
oss << "\\def \\"
489+
oss << "\\def\\"
490490
<< str_reduce(sql->col_name(col))
491-
<< " {"
491+
<< "{"
492492
<< reformat.format(0, col, sql->text(0, col))
493493
<< "}";
494494
}
495495
}
496496

497497
std::string output = oss.str();
498498

499-
// check whether line contains an \addplot command
499+
// scan lines forward and gobble all lines containing \def commands
500500
static const boost::regex
501-
re_defmacro("[[:blank:]]*(\\\\def \\\\[^}]+ \\{)[^}]+(\\}.*)");
501+
re_defmacro("[[:blank:]]*\\\\def\\\\[^{]+\\{[^}]+\\}.*");
502502
boost::smatch rm;
503503

504-
if (ln + count < m_lines.size() &&
505-
boost::regex_match(m_lines[ln], rm, re_defmacro))
506-
{
507-
m_lines.replace(ln, ln+count, indent, output, "DEFMACRO");
508-
}
509-
else
504+
size_t eln = ln;
505+
while (eln < m_lines.size() &&
506+
boost::regex_match(m_lines[eln], rm, re_defmacro))
510507
{
511-
m_lines.replace(ln, ln, indent, output, "DEFMACRO");
508+
++eln;
512509
}
510+
511+
m_lines.replace(ln, eln, indent, output, "DEFMACRO");
513512
}
514513

515514
//! process line-based file in place

tests/latex/defmacro.out

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
line
2+
%% DEFMACRO
3+
%% SELECT 42.005 AS a, 42.05 AS mc, 42.5 AS ABCD, 'hello' AS c
4+
\def\a{42.005}
5+
\def\mc{42.05}
6+
\def\ABCD{42.5}
7+
\def\c{hello}
8+
line
9+
%% DEFMACRO REFORMAT(round=0)
10+
%% SELECT 42.005 AS a, 42.05 AS mc, 42.5 AS ABCD, 'hello' AS c
11+
\def\a{42}
12+
\def\mc{42}
13+
\def\ABCD{43}
14+
\def\c{hello}
15+
line

tests/latex/defmacro.tex

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
line
2+
%% DEFMACRO
3+
%% SELECT 42.005 AS a, 42.05 AS mc, 42.5 AS ABCD, 'hello' AS c
4+
\def\gobble{this}
5+
\def\andthis{...}
6+
line
7+
%% DEFMACRO REFORMAT(round=0)
8+
%% SELECT 42.005 AS a, 42.05 AS mc, 42.5 AS ABCD, 'hello' AS c
9+
line

0 commit comments

Comments
 (0)