Skip to content

Commit 5ce5549

Browse files
committed
Fixing intelligent gobbling of lines when inserting TABTABLE.
1 parent 688a585 commit 5ce5549

3 files changed

Lines changed: 196 additions & 5 deletions

File tree

src/latex.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ class SpLatex
9494
const std::string& cmdline,
9595
const std::string& op_name,
9696
const std::string& separator,
97-
const std::string& endline);
97+
const std::string& endline,
98+
const std::string& gobble_regex);
9899

99100
//! Process % DEFMACRO commands
100101
void defmacro(size_t ln, size_t indent, const std::string& cmdline);
@@ -392,7 +393,8 @@ void SpLatex::tabular(
392393
const std::string& cmdline,
393394
const std::string& op_name,
394395
const std::string& separator,
395-
const std::string& endline)
396+
const std::string& endline,
397+
const std::string& gobble_regex)
396398
{
397399
std::string query = cmdline;
398400

@@ -452,7 +454,7 @@ void SpLatex::tabular(
452454
size_t rln = ln;
453455
size_t entry = 0;
454456

455-
static const boost::regex re_tabular(".*?\\\\\\\\(.*)");
457+
const boost::regex re_tabular(gobble_regex);
456458
boost::smatch rm;
457459

458460
// iterate over tabular lines, copy styles to replacement
@@ -575,12 +577,14 @@ SpLatex::SpLatex(TextLines& lines)
575577
else if (first_word == "TABULAR")
576578
{
577579
OUT(ln << " % " << cmd);
578-
tabular(ln, indent, cmd.substr(space_pos+1), "TABULAR", " & ", " \\\\");
580+
tabular(ln, indent, cmd.substr(space_pos+1),
581+
"TABULAR", " & ", " \\\\", ".*?\\\\\\\\(.*)");
579582
}
580583
else if (first_word == "TABTABLE")
581584
{
582585
OUT(ln << " % " << cmd);
583-
tabular(ln, indent, cmd.substr(space_pos+1), "TABTABLE", "\t", "");
586+
tabular(ln, indent, cmd.substr(space_pos+1),
587+
"TABTABLE", "\t", "", ".*\\t.*()");
584588
}
585589
else if (first_word == "DEFMACRO")
586590
{

tests/latex/tabtable1.out

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
line1
2+
% IMPORT-DATA test test.data
3+
line2
4+
%% TABTABLE SELECT testsize AS x, FLOOR(bandwidth), FLOOR(rate * 1e12), areasize
5+
%% FROM test ORDER BY x, bandwidth LIMIT 10
6+
1152 20004857425 399 1024
7+
1152 21256634665 376 1024
8+
2176 20059162540 398 2048
9+
2176 21206797610 377 2048
10+
3200 20101648154 397 3072
11+
3200 21256759869 376 3072
12+
4224 20078735758 398 4096
13+
4224 21256469275 376 4096
14+
6272 20103335011 397 6144
15+
6272 21254940419 376 6144
16+
% END TABTABLE SELECT testsize AS x, FLOOR(bandwidth), FLOOR(rate * 1e12), ar...
17+
line3
18+
indentation start
19+
%% TABTABLE SELECT testsize AS x, FLOOR(bandwidth), FLOOR(rate * 1e12), areasize
20+
%% FROM test ORDER BY x, bandwidth
21+
1152 20004857425 399 1024
22+
1152 21256634665 376 1024
23+
2176 20059162540 398 2048
24+
2176 21206797610 377 2048
25+
3200 20101648154 397 3072
26+
3200 21256759869 376 3072
27+
4224 20078735758 398 4096
28+
4224 21256469275 376 4096
29+
6272 20103335011 397 6144
30+
6272 21254940419 376 6144
31+
8320 19844289277 403 8192
32+
8320 21033549756 380 8192
33+
12416 19934071922 401 12288
34+
12416 21105216385 379 12288
35+
16512 19970353548 400 16384
36+
16512 21142325436 378 16384
37+
20608 19997700036 400 20480
38+
20608 21164943036 377 20480
39+
24704 20017094792 399 24576
40+
24704 21177968064 377 24576
41+
28800 20024361016 399 28672
42+
28800 21188091979 377 28672
43+
32896 19588722596 408 32768
44+
32896 20167090530 396 32768
45+
41088 13352542574 599 40960
46+
41088 15434595485 518 40960
47+
49280 13352656249 599 49152
48+
49280 15445744156 517 49152
49+
65664 13353218261 599 65536
50+
65664 15470586592 517 65536
51+
98432 13353616903 599 98304
52+
98432 15476290580 516 98304
53+
131200 13353488133 599 131072
54+
131200 15478200720 516 131072
55+
196736 13353703915 599 196608
56+
196736 15452726013 517 196608
57+
262272 13353783611 599 262144
58+
262272 15403930682 519 262144
59+
393344 13354375997 599 393216
60+
393344 15424185515 518 393216
61+
524416 13355357557 599 524288
62+
524416 15423989946 518 524288
63+
786560 13357098956 598 786432
64+
786560 15426535975 518 786432
65+
1048704 13322300787 600 1048576
66+
1048704 15416610336 518 1048576
67+
1310848 12599911132 634 1310720
68+
1310848 15270216963 523 1310720
69+
1572992 12597385271 635 1572864
70+
1572992 15269613288 523 1572864
71+
1835136 12593497036 635 1835008
72+
1835136 15269091481 523 1835008
73+
2097280 11814282322 677 2097152
74+
2097280 14380475033 556 2097152
75+
2359424 11732158553 681 2359296
76+
2359424 14310057139 559 2359296
77+
2621568 11151421728 717 2621440
78+
2621568 13667203078 585 2621440
79+
2883712 9635555389 830 2883584
80+
2883712 11857582908 674 2883584
81+
3145856 8830491065 905 3145728
82+
3145856 10975456216 728 3145728
83+
4194432 5703033760 1402 4194304
84+
4194432 7462653658 1072 4194304
85+
5243008 3764860746 2124 5242880
86+
5243008 5239989138 1526 5242880
87+
6291584 2970821306 2692 6291456
88+
6291584 4381387103 1825 6291456
89+
7340160 2625465946 3047 7340032
90+
7340160 4033162958 1983 7340032
91+
8388736 2448731494 3266 8388608
92+
8388736 3847558417 2079 8388608
93+
9437312 2352617641 3400 9437184
94+
9437312 3743372332 2137 9437184
95+
10485888 2288649712 3495 10485760
96+
10485888 3666709518 2181 10485760
97+
12583040 2222953585 3598 12582912
98+
12583040 3581563981 2233 12582912
99+
14680192 2195411712 3643 14680064
100+
14680192 3543382742 2257 14680064
101+
16777344 2180601210 3668 16777216
102+
16777344 3522084255 2271 16777216
103+
20971648 2170401128 3685 20971520
104+
20971648 3507422082 2280 20971520
105+
25165952 2168353166 3689 25165824
106+
25165952 3503128913 2283 25165824
107+
29360256 2167406475 3691 29360128
108+
29360256 3502572094 2284 29360128
109+
33554560 2167236950 3691 33554432
110+
33554560 3501908751 2284 33554432
111+
67108992 2167069057 3691 67108864
112+
67108992 3502477870 2284 67108864
113+
134217856 2167397762 3691 134217728
114+
134217856 3502216012 2284 134217728
115+
268435584 2167170987 3691 268435456
116+
268435584 3502080053 2284 268435456
117+
536871040 2167207622 3691 536870912
118+
536871040 3502124096 2284 536870912
119+
1073741952 2167288244 3691 1073741824
120+
1073741952 3501543006 2284 1073741824
121+
2147483776 2167167763 3691 2147483648
122+
2147483776 3501652699 2284 2147483648
123+
4294967424 2167332378 3691 4294967296
124+
4294967424 3501536124 2284 4294967296
125+
8589934720 2167234766 3691 8589934592
126+
8589934720 3501106948 2284 8589934592
127+
17179869312 2166899399 3691 17179869184
128+
17179869312 3500085763 2285 17179869184
129+
% END TABTABLE SELECT testsize AS x, FLOOR(bandwidth), FLOOR(rate * 1e12), ar...
130+
131+
%% TABTABLE SELECT testsize AS x, FLOOR(bandwidth), FLOOR(rate * 1e12), areasize
132+
%% FROM test ORDER BY x, bandwidth LIMIT 20
133+
1152 20004857425 399 1024
134+
1152 21256634665 376 1024
135+
2176 20059162540 398 2048
136+
2176 21206797610 377 2048
137+
3200 20101648154 397 3072
138+
3200 21256759869 376 3072
139+
4224 20078735758 398 4096
140+
4224 21256469275 376 4096
141+
6272 20103335011 397 6144
142+
6272 21254940419 376 6144
143+
8320 19844289277 403 8192
144+
8320 21033549756 380 8192
145+
12416 19934071922 401 12288
146+
12416 21105216385 379 12288
147+
16512 19970353548 400 16384
148+
16512 21142325436 378 16384
149+
20608 19997700036 400 20480
150+
20608 21164943036 377 20480
151+
24704 20017094792 399 24576
152+
24704 21177968064 377 24576
153+
% END TABTABLE SELECT testsize AS x, FLOOR(bandwidth), FLOOR(rate * 1e12), ar...
154+
155+
indentation end
156+
this is the end

tests/latex/tabtable1.tex

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
line1
2+
% IMPORT-DATA test test.data
3+
line2
4+
%% TABTABLE SELECT testsize AS x, FLOOR(bandwidth), FLOOR(rate * 1e12), areasize
5+
%% FROM test ORDER BY x, bandwidth LIMIT 10
6+
line3
7+
indentation start
8+
%% TABTABLE SELECT testsize AS x, FLOOR(bandwidth), FLOOR(rate * 1e12), areasize
9+
%% FROM test ORDER BY x, bandwidth
10+
1152 20004857425 399 1024
11+
1152 21256634665 376 1024
12+
2176 20059162540 398 2048
13+
2176 21206797610 377 2048
14+
3200 20101648154 397 3072
15+
3200 21256759869 376 3072
16+
4224 20078735758 398 4096
17+
% END TABTABLE SELECT testsize AS x, bandwidth, rate, areasize FROM test ORDER BY x
18+
19+
%% TABTABLE SELECT testsize AS x, FLOOR(bandwidth), FLOOR(rate * 1e12), areasize
20+
%% FROM test ORDER BY x, bandwidth LIMIT 20
21+
1152 20004857425 399 1024
22+
1152 21256634665 376 1024
23+
2176 20059162540 398 2048
24+
2176 21206797610 377 2048
25+
3200 20101648154 397 3072
26+
3200 21256759869 376 3072
27+
4224 20078735758 398 4096
28+
% END TABTABLE SELECT testsize AS x, bandwidth, rate, areasize FROM test ORDER BY x
29+
30+
indentation end
31+
this is the end

0 commit comments

Comments
 (0)