DocBook: implement REVTeX.

Improvements to abstract detection: it can now contain lists or anything with a higher depth.

Implement video floats.
This commit is contained in:
Thibaut Cuvelier 2020-11-26 06:22:27 +01:00
parent 13ab1a4d8b
commit dae0640436
11 changed files with 192 additions and 34 deletions

View File

@ -453,7 +453,7 @@ export/examples/.*/American_Mathematical_Society_%28AMS%29_docbook5
export/examples/Articles/American_Chemical_Society_%28ACS%29_docbook5
# - A&A: formula with two references (only one xml:id allowed per <equation> tag).
export/examples/Articles/Astronomy_%26_Astrophysics_docbook5
# - Elsevier: footnotes in the metadata (author footnotes are definitely not supported, though).
# - Elsevier: footnotes in the metadata (author footnotes are not supported, except maybe through annotations).
export/templates/Articles/Elsevier_docbook5
# - Branches may cause problems (especially when mixing with parts that must go in <info>).
export/export/latex/languages/supported-languages_(|babel|babel_auto-legacy)_?docbook5
@ -493,6 +493,12 @@ export/examples/(es|fr)/Modules/Linguistics_docbook5
export/examples/ko/cjk-ko-doc_docbook5
# - Metadata in abstract paragraph.
export/templates/Articles/Springers_Global_Journal_Template_%28V._3%29_docbook5
# - Sweave impossible to implement. Document irremediably wrong (no .bib file, still referenced in the text).
export/templates/Articles/R_Journal_docbook5
# - Misplaced acknowledgements (fixable).
export/templates/Articles/REVTeX_%28V._4%29_docbook5
# - Forbidden inlines, equation in formatting, broken references, float in paragraphs, videos.
export/templates/Articles/REVTeX_%28V._4.1%29_docbook5
Sublabel: docbook poster
# Posters cannot be properly exported, the LyX documents are too far from

View File

@ -31,3 +31,4 @@ export/export/docbook/Hollywood_docbook5
export/templates/Letters/French_Letter_%28lettre%29_docbook5
export/templates/Letters/Letter_%28Standard_Class%29_docbook5
export/templates/Articles/Springers_Global_Journal_Template_%28V._3%29_docbook5
export/templates/Articles/REVTeX_%28V._4%29_docbook5

View File

@ -49,7 +49,11 @@ Style Terms
End
Style Keywords
CopyStyle Terms
LatexName keywords
LabelString "Keywords:"
CopyStyle Terms
LatexName keywords
LabelString "Keywords:"
DocBookTag keyword
DocBookTagType paragraph
DocBookWrapperTag keywordset
DocBookInInfo always
End

View File

@ -215,10 +215,11 @@ Style Thanks
CopyStyle Address
LatexName thanks
LabelString "Thanks:"
DocBookTag para
DocBookWrapperTag acknowledgements
DocBookTag personname
DocBookTagType paragraph
DocBookWrapperTag othercredit
DocBookWrapperMergeWithPrevious true
DocBookInInfo never
DocBookInInfo always
End

View File

@ -226,6 +226,16 @@ Style PACS
CopyStyle Keywords
LatexName pacs
LabelString "Physics and Astronomy Classification System number:"
DocBookTag subjectset
DocBookAttr role='pacs'
DocBookTagType block
DocBookItemWrapperTag subject
DocBookItemWrapperTagType paragraph
DocBookItemTag subjectterm
DocBookItemTagType inline
DocBookWrapperTag NONE
DocBookWrapperAttr ""
DocBookInInfo always
End
@ -233,6 +243,16 @@ Style MSC
CopyStyle Keywords
LatexName ams
LabelString "Mathematics Subject Classification number:"
DocBookTag subjectset
DocBookAttr role='msc'
DocBookTagType block
DocBookItemWrapperTag subject
DocBookItemWrapperTagType paragraph
DocBookItemTag subjectterm
DocBookItemTagType inline
DocBookWrapperTag NONE
DocBookWrapperAttr ""
DocBookInInfo always
End

View File

@ -79,6 +79,11 @@ Style Affiliation
Color Green
Series Bold
EndFont
DocBookTag address
DocBookTagType paragraph
DocBookWrapperTag author
DocBookWrapperMergeWithPrevious true
DocBookInInfo always
End
@ -91,6 +96,12 @@ Style Affiliation_(alternate)
Tooltip "Optional argument to the altaffiliation command"
EndArgument
PassThru 1
DocBookTag address
DocBookAttr role='alternate'
DocBookTagType paragraph
DocBookWrapperTag author
DocBookWrapperMergeWithPrevious true
DocBookInInfo always
End
@ -123,6 +134,12 @@ Style Author_Email
TextFont
Family Roman
EndFont
DocBookTag email
DocBookTagType paragraph
DocBookWrapperTag author
DocBookWrapperTagType block
DocBookWrapperMergeWithPrevious true
DocBookInInfo always
End
@ -135,6 +152,12 @@ Style Author_URL
Tooltip "Optional argument to the homepage command"
EndArgument
PassThru 1
DocBookTag uri
DocBookTagType paragraph
DocBookWrapperTag author
DocBookWrapperTagType block
DocBookWrapperMergeWithPrevious true
DocBookInInfo always
End
@ -164,6 +187,10 @@ Style Keywords
Color Green
Series Bold
EndFont
DocBookTag keyword
DocBookTagType paragraph
DocBookWrapperTag keywordset
DocBookInInfo always
End
@ -171,6 +198,16 @@ Style PACS
CopyStyle Keywords
LatexName pacs
LabelString "PACS numbers:"
DocBookTag subjectset
DocBookAttr role='pacs'
DocBookTagType block
DocBookItemWrapperTag subject
DocBookItemWrapperTagType paragraph
DocBookItemTag subjectterm
DocBookItemTagType inline
DocBookWrapperTag NONE
DocBookWrapperAttr ""
DocBookInInfo always
End
@ -184,13 +221,22 @@ Style Preprint
BottomSep 1.5
ParSep 1.5
Align Left
DocBookWrapperTag cover
DocBookWrapperAttr role='preprint'
DocBookTag para
DocBookInInfo always
End
Style Thanks
# TODO: This style has a misleading name, innit?
CopyStyle Affiliation
LatexName thanks
LabelString "Title footnote:"
DocBookTag subtitle
DocBookAttr role='footnote'
DocBookWrapperTag NONE
DocBookInInfo maybe
End
@ -223,6 +269,8 @@ Style Acknowledgments
Size Larger
EndFont
TopSep 0.7
DocBookTag para
DocBookWrapperTag acknowledgements
End

View File

@ -55,6 +55,7 @@ Style Standard
Align Block
AlignPossible Block, Left, Right, Center
LabelType No_Label
DocBookTag para
End
@ -113,6 +114,10 @@ Style Preprint
BottomSep 1.5
ParSep 1.5
Align Left
DocBookWrapperTag cover
DocBookWrapperAttr role='preprint'
DocBookTag para
DocBookInInfo always
End
@ -149,6 +154,11 @@ Style Affiliation
LabelFont
Shape Italic
EndFont
DocBookTag address
DocBookTagType paragraph
DocBookWrapperTag author
DocBookWrapperMergeWithPrevious true
DocBookInInfo always
End
@ -162,6 +172,12 @@ Style Affiliation_(alternate)
Tooltip "Optional argument to the altaffiliation command"
EndArgument
LabelString "Affiliation (alternate):"
DocBookTag address
DocBookAttr role='alternate'
DocBookTagType paragraph
DocBookWrapperTag author
DocBookWrapperMergeWithPrevious true
DocBookInInfo always
End
@ -198,6 +214,13 @@ Style Thanks
CopyStyle Affiliation
LatexName thanks
LabelString "Thanks:"
DocBookTag personblurb
DocBookAttr role='thanks'
DocBookTagType paragraph
DocBookItemTag para
DocBookWrapperTag author
DocBookWrapperMergeWithPrevious true
DocBookInInfo always
End
@ -217,6 +240,12 @@ Style Author_Email
LabelFont
Family Roman
EndFont
DocBookTag email
DocBookTagType paragraph
DocBookWrapperTag author
DocBookWrapperTagType block
DocBookWrapperMergeWithPrevious true
DocBookInInfo always
End
@ -230,6 +259,12 @@ Style Author_URL
Tooltip "Optional argument to the homepage command"
EndArgument
LabelString "URL:"
DocBookTag uri
DocBookTagType paragraph
DocBookWrapperTag author
DocBookWrapperTagType block
DocBookWrapperMergeWithPrevious true
DocBookInInfo always
End
@ -256,6 +291,8 @@ Style Acknowledgments
Series Bold
Size Large
EndFont
DocBookTag para
DocBookWrapperTag acknowledgements
End
@ -268,6 +305,16 @@ Style PACS
LabelType Static
LabelSep M
LabelString "PACS number:"
DocBookTag subjectset
DocBookAttr role='pacs'
DocBookTagType block
DocBookItemWrapperTag subject
DocBookItemWrapperTagType paragraph
DocBookItemTag subjectterm
DocBookItemTagType inline
DocBookWrapperTag NONE
DocBookWrapperAttr ""
DocBookInInfo always
End

View File

@ -55,6 +55,8 @@ std::string Floating::docbookFloatType() const
return "table";
} else if (floattype_ == "algorithm") {
return "algorithm";
} else if (floattype_ == "video") {
return "video";
} else {
// If nothing matches, return something that will not be valid.
LYXERR0("Unrecognised float type: " + floattype_);
@ -118,7 +120,7 @@ string Floating::docbookAttr() const
string Floating::docbookTag(bool hasTitle) const
{
// TODO: configure this in the layouts?
if (docbookFloatType() == "figure" || docbookFloatType() == "algorithm") {
if (docbookFloatType() == "figure" || docbookFloatType() == "algorithm" || docbookFloatType() == "video") {
return hasTitle ? "figure" : "informalfigure";
} else if (docbookFloatType() == "table") {
return hasTitle ? "table" : "informaltable";

View File

@ -379,6 +379,9 @@ public:
/// Should the layouts that should/must go into <info> be generated?
bool docbook_generate_info = true;
/// Should wrappers be ignored? Mostly useful to avoid generation of <abstract>.
bool docbook_ignore_wrapper = false;
/// Are we generating this material for inclusion in a TOC-like entity?
bool for_toc = false;

View File

@ -757,6 +757,11 @@ void docbookNoSubfigures(XMLStream & xs, OutputParams const & runparams, const I
void InsetFloat::docbook(XMLStream & xs, OutputParams const & runparams) const
{
// if (runparams.docbook_in_par) {
// xs << xml::EndTag("para");
// xs << xml::CR();
// }
const InsetCaption* caption = getCaptionInset();
const InsetLabel* label = getLabelInset();
@ -780,6 +785,11 @@ void InsetFloat::docbook(XMLStream & xs, OutputParams const & runparams) const
docbookSubfigures(xs, runparams, caption, label, subfigures);
else
docbookNoSubfigures(xs, runparams, caption, label, ftype, this);
// if (runparams.docbook_in_par) {
// xs << xml::CR();
// xs << xml::StartTag("para");
// }
}

View File

@ -170,7 +170,7 @@ string fontToAttribute(xml::FontTypes type) {
// Higher-level convenience functions.
void openParTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar)
void openParTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar, const OutputParams & runparams)
{
if (par == prevpar)
prevpar = nullptr;
@ -182,7 +182,7 @@ void openParTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar
// next paragraph is the affiliation, then it should be output in the same <author> tag (different
// layout, same wrapper tag).
Layout const & lay = par->layout();
bool openWrapper = lay.docbookwrappertag() != "NONE";
bool openWrapper = lay.docbookwrappertag() != "NONE" && !runparams.docbook_ignore_wrapper;
if (prevpar != nullptr) {
Layout const & prevlay = prevpar->layout();
if (prevlay.docbookwrappertag() != "NONE") {
@ -209,19 +209,20 @@ void openParTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar
}
}
xml::openTag(xs, lay.docbookitemwrappertag(), lay.docbookitemwrapperattr(), lay.docbookitemwrappertagtype());
xml::openTag(xs, lay.docbookitemtag(), lay.docbookitemattr(), lay.docbookitemtagtype());
xml::openTag(xs, lay.docbookiteminnertag(), lay.docbookiteminnerattr(), lay.docbookiteminnertagtype());
}
void closeParTag(XMLStream & xs, Paragraph const * par, Paragraph const * nextpar)
void closeParTag(XMLStream & xs, Paragraph const * par, Paragraph const * nextpar, const OutputParams & runparams)
{
if (par == nextpar)
nextpar = nullptr;
// See comment in openParTag.
Layout const & lay = par->layout();
bool closeWrapper = lay.docbookwrappertag() != "NONE";
bool closeWrapper = lay.docbookwrappertag() != "NONE" && !runparams.docbook_ignore_wrapper;
if (nextpar != nullptr) {
Layout const & nextlay = nextpar->layout();
if (nextlay.docbookwrappertag() != "NONE") {
@ -236,6 +237,7 @@ void closeParTag(XMLStream & xs, Paragraph const * par, Paragraph const * nextpa
// Main logic.
xml::closeTag(xs, lay.docbookiteminnertag(), lay.docbookiteminnertagtype());
xml::closeTag(xs, lay.docbookitemtag(), lay.docbookitemtagtype());
xml::closeTag(xs, lay.docbookitemwrappertag(), lay.docbookitemwrappertagtype());
xml::closeTag(xs, lay.docbookinnertag(), lay.docbookinnertagtype());
xml::closeTag(xs, lay.docbooktag(), lay.docbooktagtype());
if (closeWrapper)
@ -412,12 +414,12 @@ void makeParagraph(
continue;
if (open_par)
openParTag(xs, &*par, prevpar);
openParTag(xs, &*par, prevpar, runparams);
xs << XMLStream::ESCAPE_NONE << parXML;
if (close_par)
closeParTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr);
closeParTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr, runparams);
}
}
@ -446,7 +448,7 @@ void makeEnvironment(Text const &text,
// Output the opening tag for this environment, but only if it has not been previously opened (condition
// implemented in openParTag).
auto prevpar = text.paragraphs().getParagraphBefore(par);
openParTag(xs, &*par, prevpar); // TODO: switch in layout for par/block?
openParTag(xs, &*par, prevpar, runparams);
// Generate the contents of this environment. There is a special case if this is like some environment.
Layout const & style = par->layout();
@ -483,7 +485,7 @@ void makeEnvironment(Text const &text,
}
// Close the environment.
closeParTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr); // TODO: switch in layout for par/block?
closeParTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr, runparams);
}
@ -630,14 +632,14 @@ void makeCommand(
// Generate this command.
auto prevpar = text.paragraphs().getParagraphBefore(par);
openParTag(xs, &*par, prevpar);
openParTag(xs, &*par, prevpar, runparams);
auto pars = par->simpleDocBookOnePar(buf, runparams,text.outerFont(distance(begin, par)));
for (auto & parXML : pars)
// TODO: decide what to do with openParTag/closeParTag in new lines.
xs << XMLStream::ESCAPE_NONE << parXML;
closeParTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr);
closeParTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr, runparams);
}
@ -737,6 +739,7 @@ DocBookInfoTag getParagraphsWithInfo(ParagraphList const &paragraphs,
// Traverse everything that might belong to <info>.
bool hasAbstractLayout = false;
depth_type abstractDepth = -1;
pit_type cpit = bpit;
for (; cpit < epit; ++cpit) {
// Skip paragraphs that don't generate anything in DocBook.
@ -755,10 +758,26 @@ DocBookInfoTag getParagraphsWithInfo(ParagraphList const &paragraphs,
// If this is marked as an abstract by the layout, put it in the right set.
if (style.docbookabstract()) {
hasAbstractLayout = true;
abstractDepth = par.getDepth();
abstractWithLayout.emplace(cpit);
continue;
}
// Deeper paragraphs following the abstract must still be considered as part of the abstract.
// For instance, this includes lists. There should not be any other kind of paragraph in between.
if (abstractDepth != -1 && style.docbookininfo() == "never") {
if (par.getDepth() > abstractDepth) {
abstractWithLayout.emplace(cpit);
continue;
}
if (par.getDepth() == abstractDepth) {
// This is not an abstract paragraph and it should not either be considered as part
// of it. It breaks the rule that abstract paragraphs must follow each other.
abstractDepth = -1;
break;
}
}
// Based on layout information, store this paragraph in one set: should be in <info>, must be,
// or abstract (either because of layout or of position).
if (style.docbookininfo() == "always")
@ -769,7 +788,7 @@ DocBookInfoTag getParagraphsWithInfo(ParagraphList const &paragraphs,
(style.docbooktag() == "NONE" || style.docbooktag() == "para") &&
style.docbookwrappertag() == "NONE")
// In this case, it is very likely that style.docbookininfo() == "never"! Be extra careful
// about anything that gets caught here.
// about anything that gets caught here. For instance, don't ake into account
abstractNoLayout.emplace(cpit);
else // This should definitely not be in <info>.
break;
@ -901,6 +920,7 @@ void outputDocBookInfo(
auto rp = runparams;
rp.docbook_generate_info = false;
rp.docbook_ignore_wrapper = true;
set<pit_type> doneParas; // Paragraphs that have already been converted (mostly to deal with lists).
for (auto const & p : info.abstract) {
@ -908,6 +928,7 @@ void outputDocBookInfo(
auto oldPar = paragraphs.iterator_at(p);
auto newPar = makeAny(text, buf, xs2, rp, oldPar);
// Find insets that should go outside the abstract.
auto subinfos = gatherInfo(oldPar);
for (auto & subinfo: subinfos)
infoInsets.insert(subinfo);
@ -968,23 +989,18 @@ void outputDocBookInfo(
// - Finally, always output the abstract as the last item of the <info>, as it requires special treatment
// (especially if it contains several paragraphs that are empty).
if (hasAbstract) {
if (info.abstractLayout) {
xs << XMLStream::ESCAPE_NONE << abstract;
xs << xml::CR();
} else {
string tag = paragraphs[*info.abstract.begin()].layout().docbookforceabstracttag();
if (tag == "NONE")
tag = "abstract";
string tag = paragraphs[*info.abstract.begin()].layout().docbookforceabstracttag();
if (tag == "NONE")
tag = "abstract";
if (!xs.isLastTagCR())
xs << xml::CR();
if (!xs.isLastTagCR())
xs << xml::CR();
xs << xml::StartTag(tag);
xs << xml::CR();
xs << XMLStream::ESCAPE_NONE << abstract;
xs << xml::EndTag(tag);
xs << xml::CR();
}
xs << xml::StartTag(tag);
xs << xml::CR();
xs << XMLStream::ESCAPE_NONE << abstract;
xs << xml::EndTag(tag);
xs << xml::CR();
}
// End the <info> tag if it was started.