Skip to content

Commit 69f60ac

Browse files
lorenzhsByteHamster
authored andcommitted
Add "|nolegend" modifier to comment out the \addlegendentry lines
1 parent 349a68c commit 69f60ac

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

src/latex.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ void SpLatex::multiplot(size_t ln, size_t indent, const std::string& cmdline)
207207
bool attrplus_mark = false;
208208
bool title_mark = false;
209209
bool ptitle_mark = false;
210+
bool nolegend_mark = false;
210211
bool xerr = false, yerr = false;
211212

212213
while (!groupfields.empty() && groupfields.back().find('|') != std::string::npos) {
@@ -223,6 +224,12 @@ void SpLatex::multiplot(size_t ln, size_t indent, const std::string& cmdline)
223224
multiplot.resize(multiplot.size() - 7);
224225
ptitle_mark = true;
225226
}
227+
else if (!groupfields.empty() && is_suffix(field, "|nolegend")) {
228+
// remove |nolegend from multiplot string
229+
field.resize(field.size() - 9);
230+
multiplot.resize(multiplot.size() - 9);
231+
nolegend_mark = true;
232+
}
226233
else if (!groupfields.empty() && is_suffix(field, "|attr")) {
227234
// remove |attr from multiplot string
228235
field.resize(field.size() - 5);
@@ -391,7 +398,7 @@ void SpLatex::multiplot(size_t ln, size_t indent, const std::string& cmdline)
391398
static const boost::regex
392399
re_addplot("[[:blank:]]*(\\\\addplot.*coordinates \\{)[^}]+(\\};.*)");
393400
static const boost::regex
394-
re_legend("[[:blank:]]*(\\\\addlegendentry\\{).*(\\};.*)");
401+
re_legend("[[:blank:]]*((?:%[[:blank:]]*)?\\\\addlegendentry\\{).*(\\};.*)");
395402

396403
boost::smatch rm;
397404

@@ -423,6 +430,9 @@ void SpLatex::multiplot(size_t ln, size_t indent, const std::string& cmdline)
423430
}
424431
else
425432
{
433+
// If |nolegend is set, comment out legend entries
434+
if (nolegend_mark)
435+
out << "% ";
426436
// add missing \addlegendentry
427437
out << "\\addlegendentry{" << legendlist[entry]
428438
<< "};" << std::endl;
@@ -458,6 +468,9 @@ void SpLatex::multiplot(size_t ln, size_t indent, const std::string& cmdline)
458468
<< " };" << std::endl;
459469
}
460470

471+
// If |nolegend is set, comment out legend entries
472+
if (nolegend_mark)
473+
out << "% ";
461474
out << "\\addlegendentry{" << legendlist[entry]
462475
<< "};" << std::endl;
463476

0 commit comments

Comments
 (0)