]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCitation.cpp
Allow LyX to find pdfs and urls of citation references and follow them from context...
[lyx.git] / src / insets / InsetCitation.cpp
1 /**
2  * \file InsetCitation.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  * \author Herbert Voß
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "InsetCitation.h"
15
16 #include "BiblioInfo.h"
17 #include "Buffer.h"
18 #include "buffer_funcs.h"
19 #include "BufferParams.h"
20 #include "BufferView.h"
21 #include "DispatchResult.h"
22 #include "FuncCode.h"
23 #include "FuncRequest.h"
24 #include "FuncStatus.h"
25 #include "LaTeXFeatures.h"
26 #include "LyX.h"
27 #include "output_xhtml.h"
28 #include "output_docbook.h"
29 #include "ParIterator.h"
30 #include "texstream.h"
31 #include "TocBackend.h"
32
33 #include "support/debug.h"
34 #include "support/docstream.h"
35 #include "support/FileNameList.h"
36 #include "support/gettext.h"
37 #include "support/lstrings.h"
38
39 #include <algorithm>
40 #include <climits>
41
42 using namespace std;
43 using namespace lyx::support;
44
45 namespace lyx {
46
47 InsetCitation::InsetCitation(Buffer * buf, InsetCommandParams const & p)
48         : InsetCommand(buf, p)
49 {
50         buffer().removeBiblioTempFiles();
51 }
52
53
54 InsetCitation::~InsetCitation()
55 {
56         if (isBufferLoaded())
57                 /* We do not use buffer() because Coverity believes that this
58                  * may throw an exception. Actually this code path is not
59                  * taken when buffer_ == 0 */
60                 buffer_->removeBiblioTempFiles();
61 }
62
63
64 // May well be over-ridden when session settings are loaded
65 // in GuiCitation. Unfortunately, that will not happen until
66 // such a dialog is created.
67 bool InsetCitation::last_literal = true;
68
69
70 ParamInfo const & InsetCitation::findInfo(string const & /* cmdName */)
71 {
72         static ParamInfo param_info_;
73
74         // standard cite does only take one argument, but biblatex, jurabib
75         // and natbib extend this to two arguments, so
76         // we have to allow both here. InsetCitation takes care that
77         // LaTeX output is nevertheless correct.
78         if (param_info_.empty()) {
79                 param_info_.add("after", ParamInfo::LATEX_OPTIONAL,
80                                 ParamInfo::HANDLING_LATEXIFY);
81                 param_info_.add("before", ParamInfo::LATEX_OPTIONAL,
82                                 ParamInfo::HANDLING_LATEXIFY);
83                 param_info_.add("key", ParamInfo::LATEX_REQUIRED);
84                 param_info_.add("pretextlist", ParamInfo::LATEX_OPTIONAL,
85                                 ParamInfo::HANDLING_LATEXIFY);
86                 param_info_.add("posttextlist", ParamInfo::LATEX_OPTIONAL,
87                                 ParamInfo::HANDLING_LATEXIFY);
88                 param_info_.add("literal", ParamInfo::LYX_INTERNAL);
89         }
90         return param_info_;
91 }
92
93
94 // We allow any command here, since we fall back to cite
95 // anyway if a command is not allowed by a style
96 bool InsetCitation::isCompatibleCommand(string const &)
97 {
98         return true;
99 }
100
101
102 CitationStyle InsetCitation::getCitationStyle(BufferParams const & bp, string const & input,
103                                   vector<CitationStyle> const & valid_styles) const
104 {
105         CitationStyle cs = valid_styles[0];
106         cs.forceUpperCase = false;
107         cs.hasStarredVersion = false;
108
109         string normalized_input = input;
110         string::size_type const n = input.size() - 1;
111         if (isUpperCase(input[0]))
112                 normalized_input[0] = lowercase(input[0]);
113         if (input[n] == '*')
114                 normalized_input = normalized_input.substr(0, n);
115
116         string const alias = bp.getCiteAlias(normalized_input);
117         if (!alias.empty())
118                 normalized_input = alias;
119
120         vector<CitationStyle>::const_iterator it  = valid_styles.begin();
121         vector<CitationStyle>::const_iterator end = valid_styles.end();
122         for (; it != end; ++it) {
123                 CitationStyle this_cs = *it;
124                 if (this_cs.name == normalized_input) {
125                         cs = *it;
126                         break;
127                 }
128         }
129
130         return cs;
131 }
132
133
134 void InsetCitation::doDispatch(Cursor & cur, FuncRequest & cmd)
135 {
136         switch (cmd.action()) {
137         case LFUN_INSET_EDIT:
138                 openCitation();
139                 break;
140         case LFUN_INSET_MODIFY: {
141                 buffer().removeBiblioTempFiles();
142                 cache.recalculate = true;
143                 if (cmd.getArg(0) == "toggleparam") {
144                         string cmdname = getCmdName();
145                         string const alias =
146                                 buffer().masterParams().getCiteAlias(cmdname);
147                         if (!alias.empty())
148                                 cmdname = alias;
149                         string const par = cmd.getArg(1);
150                         string newcmdname = cmdname;
151                         if (par == "star") {
152                                 if (suffixIs(cmdname, "*"))
153                                         newcmdname = rtrim(cmdname, "*");
154                                 else
155                                         newcmdname = cmdname + "*";
156                         } else if (par == "casing") {
157                                 if (isUpperCase(cmdname[0]))
158                                         newcmdname[0] = lowercase(cmdname[0]);
159                                 else
160                                         newcmdname[0] = uppercase(newcmdname[0]);
161                         }
162                         cmd = FuncRequest(LFUN_INSET_MODIFY, "changetype " + newcmdname);
163                 }
164         }
165         // fall through
166         default:
167                 InsetCommand::doDispatch(cur, cmd);
168         }
169 }
170
171
172 void InsetCitation::openCitation(){
173         Buffer const & buf = *buffer_;
174         // Only after the buffer is loaded from file...
175         if (!buf.isFullyLoaded())
176                 return;
177
178         BiblioInfo const & bi = buf.masterBibInfo();
179         if (bi.empty())
180                 return;
181
182         docstring const & key = getParam("key");
183         if (key.empty())
184                 return;
185
186         vector<docstring> keys = getVectorFromString(key);
187         docstring year, author, doi, url, file;
188         for (docstring const & kvar : keys) {
189                 year = bi.getYear(kvar, buffer(), false);
190                 author = bi.getAuthorOrEditorList(kvar, buffer());
191                 bi.getLocators(kvar, doi, url, file);
192                 LYXERR(Debug::INSETS, "Locators: doi:" << doi << " url:"
193                         << url << " file:" << file << " author:" << author << " year:" << year);
194                 docstring locator;
195                 if (!file.empty()) {
196                         locator = file;
197                 } else if (!doi.empty()) {
198                         locator = doi;
199                 } else if (!url.empty()) {
200                         locator = url;
201                 } else {
202                         locator = "EXTERNAL " +  year + " " + author;
203                 }
204                 FuncRequest cmd = FuncRequest(LFUN_CITATION_OPEN, locator);
205                 lyx::dispatch(cmd);
206         }
207 }
208
209
210 bool InsetCitation::getStatus(Cursor & cur, FuncRequest const & cmd,
211         FuncStatus & status) const
212 {
213         switch (cmd.action()) {
214         // Handle the alias case
215         case LFUN_INSET_MODIFY:
216                 if (cmd.getArg(0) == "changetype") {
217                         string cmdname = getCmdName();
218                         string const alias =
219                                 buffer().masterParams().getCiteAlias(cmdname);
220                         if (!alias.empty())
221                                 cmdname = alias;
222                         if (suffixIs(cmdname, "*"))
223                                 cmdname = rtrim(cmdname, "*");
224                         string const newtype = cmd.getArg(1);
225                         status.setEnabled(isCompatibleCommand(newtype));
226                         status.setOnOff(newtype == cmdname);
227                 }
228                 if (cmd.getArg(0) == "toggleparam") {
229                         string cmdname = getCmdName();
230                         string const alias =
231                                 buffer().masterParams().getCiteAlias(cmdname);
232                         if (!alias.empty())
233                                 cmdname = alias;
234                         vector<CitationStyle> citation_styles =
235                                 buffer().masterParams().citeStyles();
236                         CitationStyle cs = getCitationStyle(buffer().masterParams(),
237                                                             cmdname, citation_styles);
238                         if (cmd.getArg(1) == "star") {
239                                 status.setEnabled(cs.hasStarredVersion);
240                                 status.setOnOff(suffixIs(cmdname, "*"));
241                         }
242                         else if (cmd.getArg(1) == "casing") {
243                                 status.setEnabled(cs.forceUpperCase);
244                                 status.setOnOff(isUpperCase(cmdname[0]));
245                         }
246                 }
247                 return true;
248         case LFUN_INSET_EDIT:
249                 return true;
250         default:
251                 return InsetCommand::getStatus(cur, cmd, status);
252         }
253 }
254
255
256 bool InsetCitation::addKey(string const & key)
257 {
258         docstring const ukey = from_utf8(key);
259         docstring const & curkeys = getParam("key");
260         if (curkeys.empty()) {
261                 setParam("key", ukey);
262                 cache.recalculate = true;
263                 return true;
264         }
265
266         vector<docstring> keys = getVectorFromString(curkeys);
267         vector<docstring>::const_iterator it = keys.begin();
268         vector<docstring>::const_iterator en = keys.end();
269         for (; it != en; ++it) {
270                 if (*it == ukey) {
271                         LYXERR0("Key " << key << " already present.");
272                         return false;
273                 }
274         }
275         keys.push_back(ukey);
276         setParam("key", getStringFromVector(keys));
277         cache.recalculate = true;
278         return true;
279 }
280
281
282 docstring InsetCitation::toolTip(BufferView const & bv, int, int) const
283 {
284         Buffer const & buf = bv.buffer();
285         // Only after the buffer is loaded from file...
286         if (!buf.isFullyLoaded())
287                 return docstring();
288
289         BiblioInfo const & bi = buf.masterBibInfo();
290         if (bi.empty())
291                 return _("No bibliography defined!");
292
293         docstring const & key = getParam("key");
294         if (key.empty())
295                 return _("No citations selected!");
296
297         CiteItem ci;
298         ci.richtext = true;
299         vector<docstring> keys = getVectorFromString(key);
300         if (keys.size() == 1)
301                 return bi.getInfo(keys[0], buffer(), ci);
302
303         docstring tip;
304         tip += "<ol>";
305         int count = 0;
306         for (docstring const & kvar : keys) {
307                 docstring const key_info = bi.getInfo(kvar, buffer(), ci);
308                 // limit to reasonable size.
309                 if (count > 9 && keys.size() > 11) {
310                         tip.push_back(0x2026);// HORIZONTAL ELLIPSIS
311                         tip += "<p>"
312                                 + bformat(_("+ %1$d more entries."), int(keys.size() - count))
313                                 + "</p>";
314                         break;
315                 }
316                 if (key_info.empty())
317                         continue;
318                 tip += "<li>" + key_info + "</li>";
319                 ++count;
320         }
321         tip += "</ol>";
322         return tip;
323 }
324
325
326 namespace {
327
328 CitationStyle asValidLatexCommand(BufferParams const & bp, string const & input,
329                                   vector<CitationStyle> const & valid_styles)
330 {
331         CitationStyle cs = valid_styles[0];
332         cs.forceUpperCase = false;
333         cs.hasStarredVersion = false;
334
335         string normalized_input = input;
336         string::size_type const n = input.size() - 1;
337         if (isUpperCase(input[0]))
338                 normalized_input[0] = lowercase(input[0]);
339         if (input[n] == '*')
340                 normalized_input = normalized_input.substr(0, n);
341
342         string const alias = bp.getCiteAlias(normalized_input);
343         if (!alias.empty())
344                 normalized_input = alias;
345
346         vector<CitationStyle>::const_iterator it  = valid_styles.begin();
347         vector<CitationStyle>::const_iterator end = valid_styles.end();
348         for (; it != end; ++it) {
349                 CitationStyle this_cs = *it;
350                 if (this_cs.name == normalized_input) {
351                         cs = *it;
352                         break;
353                 }
354         }
355
356         cs.forceUpperCase &= input[0] == uppercase(input[0]);
357         cs.hasStarredVersion &= input[n] == '*';
358
359         return cs;
360 }
361
362
363 inline docstring wrapCitation(docstring const & key,
364                 docstring const & content, bool for_xhtml)
365 {
366         if (!for_xhtml)
367                 return content;
368         // we have to do the escaping here, because we will ultimately
369         // write this as a raw string, so as not to escape the tags.
370         return "<a href='#LyXCite-" + xml::cleanAttr(key) + "'>" +
371                         xml::escapeString(content, XMLStream::ESCAPE_ALL) + "</a>";
372 }
373
374 } // anonymous namespace
375
376
377 vector<pair<docstring, docstring>> InsetCitation::getQualifiedLists(docstring const & p) const
378 {
379         vector<docstring> ps =
380                 getVectorFromString(p, from_ascii("\t"));
381         QualifiedList res;
382         for (docstring const & s: ps) {
383                 docstring key = s;
384                 docstring val;
385                 if (contains(s, ' '))
386                         val = split(s, key, ' ');
387                 res.push_back(make_pair(key, val));
388         }
389         return res;
390 }
391
392 docstring InsetCitation::generateLabel(bool for_xhtml) const
393 {
394         docstring label;
395         label = complexLabel(for_xhtml);
396
397         // Fallback to fail-safe
398         if (label.empty())
399                 label = basicLabel(for_xhtml);
400
401         return label;
402 }
403
404
405 docstring InsetCitation::complexLabel(bool for_xhtml) const
406 {
407         Buffer const & buf = buffer();
408         // Only start the process off after the buffer is loaded from file.
409         if (!buf.isFullyLoaded())
410                 return docstring();
411
412         docstring const & key = getParam("key");
413
414         BiblioInfo const & biblist = buf.masterBibInfo();
415
416         // mark broken citations
417         setBroken(false);
418
419         if (biblist.empty()) {
420                 setBroken(true);
421                 return docstring();
422         }
423
424         if (key.empty())
425                 return _("No citations selected!");
426
427         // check all citations
428         // we only really want the last 'false', to suppress trimming, but
429         // we need to give the other defaults, too, to set it.
430         vector<docstring> keys =
431                 getVectorFromString(key, from_ascii(","), false, false);
432         for (auto const & k : keys) {
433                 if (biblist.find(k) == biblist.end()) {
434                         setBroken(true);
435                         break;
436                 }
437         }
438         
439         string cite_type = getCmdName();
440         bool const uppercase = isUpperCase(cite_type[0]);
441         if (uppercase)
442                 cite_type[0] = lowercase(cite_type[0]);
443         bool const starred = (cite_type[cite_type.size() - 1] == '*');
444         if (starred)
445                 cite_type = cite_type.substr(0, cite_type.size() - 1);
446
447         // handle alias
448         string const alias = buf.masterParams().getCiteAlias(cite_type);
449         if (!alias.empty())
450                 cite_type = alias;
451
452         // FIXME: allow to add cite macros
453         /*
454         buffer().params().documentClass().addCiteMacro("!textbefore", to_utf8(before));
455         buffer().params().documentClass().addCiteMacro("!textafter", to_utf8(after));
456         */
457         docstring label;
458         CitationStyle cs = getCitationStyle(buffer().masterParams(),
459                         cite_type, buffer().masterParams().citeStyles());
460         bool const qualified = cs.hasQualifiedList
461                 && (keys.size() > 1
462                     || !getParam("pretextlist").empty()
463                     || !getParam("posttextlist").empty());
464         QualifiedList pres = getQualifiedLists(getParam("pretextlist"));
465         QualifiedList posts = getQualifiedLists(getParam("posttextlist"));
466
467         CiteItem ci;
468         ci.textBefore = getParam("before");
469         ci.textAfter = getParam("after");
470         ci.forceUpperCase = uppercase;
471         ci.Starred = starred;
472         ci.max_size = UINT_MAX;
473         ci.isQualified = qualified;
474         ci.pretexts = pres;
475         ci.posttexts = posts;
476         if (for_xhtml) {
477                 ci.max_key_size = UINT_MAX;
478                 ci.context = CiteItem::Export;
479         }
480         ci.richtext = for_xhtml;
481         label = biblist.getLabel(keys, buffer(), cite_type, ci);
482         return label;
483 }
484
485
486 docstring InsetCitation::basicLabel(bool for_xhtml) const
487 {
488         docstring keys = getParam("key");
489         docstring label;
490
491         docstring key;
492         do {
493                 // if there is no comma, then everything goes into key
494                 // and keys will be empty.
495                 keys = split(keys, key, ',');
496                 if (!label.empty())
497                         label += ", ";
498                 label += wrapCitation(key, key, for_xhtml);
499         } while (!keys.empty());
500
501         docstring const & after = getParam("after");
502         if (!after.empty())
503                 label += ", " + after;
504
505         return '[' + label + ']';
506 }
507
508
509 bool InsetCitation::forceLTR(OutputParams const & rp) const
510 {
511         // We have to force LTR for numeric references
512         // [= bibliography, plain BibTeX, numeric natbib
513         // and biblatex]. Except for XeTeX/bidi. See #3005.
514         if (rp.useBidiPackage())
515                 return false;
516         return (buffer().masterParams().citeEngine() == "basic"
517                 || buffer().masterParams().citeEngineType() == ENGINE_TYPE_NUMERICAL);
518 }
519
520 docstring InsetCitation::screenLabel() const
521 {
522         return cache.screen_label;
523 }
524
525
526 void InsetCitation::updateBuffer(ParIterator const &, UpdateType, bool const /*deleted*/)
527 {
528         if (!cache.recalculate && buffer().citeLabelsValid())
529                 return;
530         // The label may have changed, so we have to re-create it.
531         docstring const glabel = generateLabel();
532         cache.recalculate = false;
533         cache.generated_label = glabel;
534         unsigned int const maxLabelChars = 45;
535         cache.screen_label = glabel;
536         support::truncateWithEllipsis(cache.screen_label, maxLabelChars, true);
537 }
538
539
540 void InsetCitation::addToToc(DocIterator const & cpit, bool output_active,
541                                                          UpdateType, TocBackend & backend) const
542 {
543         // NOTE
544         // BiblioInfo::collectCitedEntries() uses the TOC to collect the citations
545         // from the document. It is used indirectly, via BiblioInfo::makeCitationLables,
546         // by both XHTML and plaintext output. So, if we change what goes into the TOC,
547         // then we will also need to change that routine.
548         docstring tocitem;
549         if (isBroken())
550                 tocitem = _("BROKEN: ");
551         tocitem += getParam("key");
552         TocBuilder & b = backend.builder("citation");
553         b.pushItem(cpit, tocitem, output_active);
554         b.pop();
555         if (isBroken()) {
556                 shared_ptr<Toc> toc2 = backend.toc("brokenrefs");
557                 toc2->push_back(TocItem(cpit, 0, tocitem, output_active));
558         }
559 }
560
561
562 int InsetCitation::plaintext(odocstringstream & os,
563        OutputParams const &, size_t) const
564 {
565         string const & cmd = getCmdName();
566         if (cmd == "nocite")
567                 return 0;
568
569         docstring const label = generateLabel(false);
570         os << label;
571         return label.size();
572 }
573
574
575 static docstring const cleanupWhitespace(docstring const & citelist)
576 {
577         docstring::const_iterator it  = citelist.begin();
578         docstring::const_iterator end = citelist.end();
579         // Paranoia check: make sure that there is no whitespace in here
580         // -- at least not behind commas or at the beginning
581         docstring result;
582         char_type last = ',';
583         for (; it != end; ++it) {
584                 if (*it != ' ')
585                         last = *it;
586                 if (*it != ' ' || last != ',')
587                         result += *it;
588         }
589         return result;
590 }
591
592
593 void InsetCitation::docbook(XMLStream & xs, OutputParams const &) const
594 {
595         if (getCmdName() == "nocite")
596                 return;
597
598         // Split the different citations (on ","), so that one tag can be output for each of them.
599         // DocBook does not support having multiple citations in one tag, so that we have to deal with formatting here.
600         docstring citations = getParam("key");
601         if (citations.find(',') == string::npos) {
602                 xs << xml::CompTag("biblioref", "endterm=\"" + to_utf8(xml::cleanID(citations)) + "\"");
603         } else {
604                 size_t pos = 0;
605                 while (pos != string::npos) {
606                         pos = citations.find(',');
607                         xs << xml::CompTag("biblioref", "endterm=\"" + to_utf8(xml::cleanID(citations.substr(0, pos))) + "\"");
608                         citations.erase(0, pos + 1);
609
610                         if (pos != string::npos) {
611                                 xs << ", "; 
612                         }
613                 }
614         }
615 }
616
617
618 docstring InsetCitation::xhtml(XMLStream & xs, OutputParams const &) const
619 {
620         if (getCmdName() == "nocite")
621                 return docstring();
622
623         // have to output this raw, because generateLabel() will include tags
624         xs << XMLStream::ESCAPE_NONE << generateLabel(true);
625
626         return docstring();
627 }
628
629
630 void InsetCitation::toString(odocstream & os) const
631 {
632         odocstringstream ods;
633         plaintext(ods, OutputParams(0));
634         os << ods.str();
635 }
636
637
638 void InsetCitation::forOutliner(docstring & os, size_t const, bool const) const
639 {
640         os += screenLabel();
641 }
642
643
644 // Have to overwrite the default InsetCommand method in order to check that
645 // the \cite command is valid. Eg, the user has natbib enabled, inputs some
646 // citations and then changes his mind, turning natbib support off. The output
647 // should revert to the default citation command as provided by the citation
648 // engine, e.g. \cite[]{} for the basic engine.
649 void InsetCitation::latex(otexstream & os, OutputParams const & runparams) const
650 {
651         // When this is a child compiled on its own, we use the children
652         // own bibinfo, else the master's
653         BiblioInfo const & bi = runparams.is_child
654                         ? buffer().masterBibInfo() : buffer().bibInfo();
655         docstring const key = getParam("key");
656         // "keyonly" command: output the plain key and stop.
657         if (getCmdName() == "keyonly") {
658                 // Special command to only return the key
659                 if (!bi.isBibtex(getParam("key")))
660                         // escape chars with bibitems
661                         os << escape(cleanupWhitespace(key));
662                 else
663                         os << cleanupWhitespace(key);
664                 return;
665         }
666         vector<CitationStyle> citation_styles = buffer().masterParams().citeStyles();
667         CitationStyle cs = asValidLatexCommand(buffer().masterParams(),
668                                                getCmdName(), citation_styles);
669         // FIXME UNICODE
670         docstring const cite_str = from_utf8(citationStyleToString(cs, true));
671
672         // check if we have to do a qualified list
673         vector<docstring> keys = getVectorFromString(cleanupWhitespace(key));
674         bool const qualified = cs.hasQualifiedList
675                 && (!getParam("pretextlist").empty()
676                     || !getParam("posttextlist").empty());
677
678         if (runparams.inulemcmd > 0)
679                 os << "\\mbox{";
680
681         os << "\\" << cite_str;
682
683         if (qualified)
684                 os << "s";
685
686         ParamInfo const & pinfo = findInfo(string());
687         docstring before = params().prepareCommand(runparams, getParam("before"),
688                                                    pinfo["before"].handling());
689         docstring after = params().prepareCommand(runparams, getParam("after"),
690                                                    pinfo["after"].handling());
691         if (!before.empty() && cs.textBefore) {
692                 if (qualified)
693                         os << '(' << protectArgument(before, '(', ')')
694                            << ")(" << protectArgument(after, '(', ')') << ')';
695                 else
696                         os << '[' << protectArgument(before) << "]["
697                            << protectArgument(after) << ']';
698         } else if (!after.empty() && cs.textAfter) {
699                 if (qualified)
700                         os << '(' << protectArgument(after, '(', ')') << ')';
701                 else
702                         os << '[' << protectArgument(after) << ']';
703         }
704
705         if (!bi.isBibtex(key))
706                 // escape chars with bibitems
707                 os << '{' << escape(cleanupWhitespace(key)) << '}';
708         else {
709                 if (qualified) {
710                         QualifiedList pres = getQualifiedLists(getParam("pretextlist"));
711                         QualifiedList posts = getQualifiedLists(getParam("posttextlist"));
712                         for (docstring const & k : keys) {
713                                 docstring prenote;
714                                 QualifiedList::iterator it = pres.begin();
715                                 for (; it != pres.end() ; ++it) {
716                                         if ((*it).first == k) {
717                                                 prenote = (*it).second;
718                                                 pres.erase(it);
719                                                 break;
720                                         }
721                                 }
722                                 docstring bef = params().prepareCommand(runparams, prenote,
723                                                    pinfo["pretextlist"].handling());
724                                 docstring postnote;
725                                 QualifiedList::iterator pit = posts.begin();
726                                 for (; pit != posts.end() ; ++pit) {
727                                         if ((*pit).first == k) {
728                                                 postnote = (*pit).second;
729                                                 posts.erase(pit);
730                                                 break;
731                                         }
732                                 }
733                                 docstring aft = params().prepareCommand(runparams, postnote,
734                                                    pinfo["posttextlist"].handling());
735                                 if (!bef.empty())
736                                         os << '[' << protectArgument(bef)
737                                            << "][" << protectArgument(aft) << ']';
738                                 else if (!aft.empty())
739                                         os << '[' << protectArgument(aft) << ']';
740                                 os << '{' << k << '}';
741                         }
742                 } else
743                         os << '{' << cleanupWhitespace(key) << '}';
744         }
745
746         if (runparams.inulemcmd)
747                 os << "}";
748 }
749
750
751 string InsetCitation::contextMenuName() const
752 {
753         return "context-citation";
754 }
755
756
757 } // namespace lyx