From 739735ab73e46d8f7c64b8f78ce7265a711b8468 Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Sun, 18 Oct 2020 08:15:54 +0200 Subject: [PATCH] DocBook: output inline equations in their own paragraph if they are the only inset of the paragraph. It's invalid to have an outside a paragraph. Another solution would have been to change InsetMathHull::docbook to generate an , but that function would have required more knowledge about its context than now. Need more tests to determine if should only be output for hullSimple or in more cases like: const static std::set inlineHulls = { hullUnknown, hullNone, hullSimple, hullEquation, hullMultline, hullGather, hullRegexp }; --- autotests/export/docbook/doc_de_Math.lyx | 324 +++++++++++++++++++++++ autotests/export/docbook/doc_de_Math.xml | 23 ++ src/output_docbook.cpp | 4 +- 3 files changed, 350 insertions(+), 1 deletion(-) create mode 100644 autotests/export/docbook/doc_de_Math.lyx create mode 100644 autotests/export/docbook/doc_de_Math.xml diff --git a/autotests/export/docbook/doc_de_Math.lyx b/autotests/export/docbook/doc_de_Math.lyx new file mode 100644 index 0000000000..a0e9bf2dcc --- /dev/null +++ b/autotests/export/docbook/doc_de_Math.lyx @@ -0,0 +1,324 @@ +#LyX 2.4 created this file. For more info see https://www.lyx.org/ +\lyxformat 599 +\begin_document +\begin_header +\save_transient_properties true +\origin unavailable +\textclass scrartcl +\begin_preamble +% DO NOT ALTER THIS PREAMBLE!!! +% +% This preamble is designed to ensure that the file prints +% out as advertised. If you mess with this preamble, +% parts of this document may not print out as expected. If you +% have problems LaTeXing this file, please contact +% the documentation team +% email: lyx-docs@lists.lyx.org + +% Folgendes Problem lösen: +% Besteht die Kapitelnummer aus zu vielen Ziffern, wird die +% Kapitelüberschrift im Inhaltsverzeichnis direkt an oder über +% die Kapitelnummer geschrieben. +% Als Lösung wird mehr Platz zwischen Nummer und +% Überschrift eingefügt. +\renewcommand{\l@subsection}{\@dottedtocline{2}{1.5em}{2.8em}} +\renewcommand{\l@subsubsection}{\@dottedtocline{3}{4.3em}{3.6em}} + +% Linkfläche für Querverweise vergrößern und automatisch benennen, +\AtBeginDocument{\renewcommand{\ref}[1]{\mbox{\autoref{#1}}}} +\@ifpackageloaded{babel}{ + \addto\extrasngerman{% + \renewcommand*{\equationautorefname}[1]{}% + \renewcommand{\sectionautorefname}{Kap.\negthinspace}% + \renewcommand{\subsectionautorefname}{Kap.\negthinspace}% + \renewcommand{\subsubsectionautorefname}{Kap.\negthinspace}% + } +}{} + +% Makros damit Pakete nicht doppelt geladen werden. +% siehe erste Fußnote in Kap. 9.3 +\@ifundefined{textcolor}{\usepackage{color}}{} + +% Die Seiten des Inhaltsverzeichnisses werden römisch numeriert, +% ein PDF-Lesezeichen für das Inhaltsverzeichnis wird hinzugefügt +\pagenumbering{roman} +\let\myTOC\tableofcontents +\renewcommand{\tableofcontents}{% + \vspace{1cm} + \pdfbookmark[1]{\contentsname}{} + \myTOC + \cleardoublepage + \pagenumbering{arabic}} + +% add 0.5 mm vertical space for table rows +\@ifundefined{extrarowheight} {\usepackage{array}}{} +\setlength{\extrarowheight}{0.5mm} + +% Damit die Fußnoten einen zusätzlichen vertikalen Abstand von 1,5 mm haben, +\let\myFoot\footnote +\renewcommand{\footnote}[1]{\myFoot{#1\vspace{1.5mm}}} + +% macht Beschriftungen fett +\setkomafont{captionlabel}{\bfseries} + +% enables calculation of values +\usepackage{calc} + +% für Mehrfachzeilen, benutzt in Kap. 24.7 +\usepackage{multicol} + +% benutzt in Kap. 19.4 +\usepackage{remreset} + +% für das Fourier-Transformationssymbol +\usepackage{mathrsfs} + +% Farbdefinition aus Kap. 9.3 +\definecolor{dunkelgruen}{cmyk}{0.5, 0, 1, 0.5} + +% Operatoren deklarieren (siehe Kap. 10.4 und 15.2) +\DeclareMathOperator*{\Raute}{\blacklozenge} +\DeclareMathOperator{\sgn}{sgn} + +% Beispielbefehle aus Kap. 20.1 +\newcommand{\gr}{\Longrightarrow} +\newcommand{\us}[1]{\underline{#1}} +\newcommand{\fb}[3]{\framebox#1#2{$#3$}} +\newcommand{\cb}[3][white]{\fcolorbox{#2}{#1}{$#3$}} +\newcommand{\fracS}[3][]{\genfrac{}{}{#1}{}{#2}{#3}} + +% Beispielmakro aus Kap. 19.4 +%\AtBeginDocument{ +%\def\tagform@#1{\maketag@@@{|#1|}} +%} + +\@ifpackageloaded{babel}{ + % Damit der Index einen anderen Namen erhält. + \addto\captionsngerman + {\renewcommand{\indexname} + {Stichwort- und Befehlsverzeichnis}} +}{} + +% ------------------------------------ +% used to check for needed LaTeX packages +\usepackage{ifthen} + +% testen ob das Paket undertilde installiert ist +% wird benutzt für den Befehl \utilde +\newboolean{undertilde} +\IfFileExists{undertilde.sty} + {\usepackage{undertilde} + \setboolean{undertilde}{true}} + {\setboolean{undertilde}{false}} + +% testen ob das Paket eurosym installiert ist +% wird benutzt für das Euro-Symbol +\newboolean{eurosym} +\IfFileExists{eurosym.sty} + {\usepackage[gennarrow]{eurosym} + \setboolean{eurosym}{true}} + {\setboolean{eurosym}{false}} + +% testen ob Paket braket installiert ist +% benötigt für physikalische Vektoren +\newboolean{braket} +\IfFileExists{braket.sty} + {\usepackage{braket} + \setboolean{braket}{true}} + {\setboolean{braket}{false}} + +% testen ob Paket cancel installiert ist +\newboolean{cancel} +\IfFileExists{cancel.sty} + {\usepackage{cancel} + \setboolean{cancel}{true}} + {\setboolean{cancel}{false}} + +% testen ob Paket upgreek installiert ist +\newboolean{upgreek} +\IfFileExists{upgreek.sty} + {\usepackage{upgreek} + \setboolean{upgreek}{true}} + {\setboolean{upgreek}{false}} + +% benötigt für Kommas in Formeln, siehe Kap. 22.3 +\IfFileExists{icomma.sty} + {\usepackage{icomma}}{} +% Added by lyx2lyx +\setlength{\parskip}{\medskipamount} +\setlength{\parindent}{0pt} +\end_preamble +\options bibliography=totoc,index=totoc,BCOR7.5mm,titlepage,captions=tableheading +\use_default_options false +\begin_modules +subequations +\end_modules +\maintain_unincluded_children no +\language ngerman +\language_package default +\inputencoding utf8 +\fontencoding auto +\font_roman "lmodern" "default" +\font_sans "lmss" "default" +\font_typewriter "lmtt" "default" +\font_math "auto" "auto" +\font_default_family default +\use_non_tex_fonts false +\font_sc false +\font_roman_osf false +\font_sans_osf false +\font_typewriter_osf false +\font_sf_scale 100 100 +\font_tt_scale 100 100 +\use_microtype false +\use_dash_ligatures false +\graphics default +\default_output_format pdf2 +\output_sync 0 +\bibtex_command default +\index_command makeindex +\paperfontsize 12 +\spacing single +\use_hyperref true +\pdf_title "LyXs Mathehandbuch" +\pdf_author "LyX Team, Uwe Stöhr" +\pdf_subject "LyX-Dokumentation der Mathefunktionen" +\pdf_keywords "LyX, Mathed" +\pdf_bookmarks true +\pdf_bookmarksnumbered true +\pdf_bookmarksopen true +\pdf_bookmarksopenlevel 1 +\pdf_breaklinks false +\pdf_pdfborder false +\pdf_colorlinks true +\pdf_backref false +\pdf_pdfusetitle false +\pdf_quoted_options "linkcolor=black, citecolor=black, urlcolor=blue, filecolor=blue, pdfpagelayout=OneColumn, pdfnewwindow=true, pdfstartview=XYZ, plainpages=false" +\papersize a4 +\use_geometry false +\use_package amsmath 2 +\use_package amssymb 2 +\use_package cancel 1 +\use_package esint 1 +\use_package mathdots 1 +\use_package mathtools 2 +\use_package mhchem 1 +\use_package stackrel 1 +\use_package stmaryrd 1 +\use_package undertilde 0 +\cite_engine basic +\cite_engine_type default +\biblio_style plain +\use_bibtopic false +\use_indices false +\paperorientation portrait +\suppress_date false +\justification true +\use_refstyle 0 +\use_minted 0 +\use_lineno 0 +\notefontcolor #0000ff +\index Stichwortverzeichnis +\shortcut idx +\color #008000 +\end_index +\secnumdepth 4 +\tocdepth 3 +\paragraph_separation indent +\paragraph_indentation default +\is_math_indent 0 +\math_numbering_side default +\quotes_style german +\dynamic_quotes 0 +\papercolumns 1 +\papersides 2 +\paperpagestyle plain +\tablestyle default +\bullet 1 0 6 -1 +\bullet 2 2 35 -1 +\bullet 3 2 7 -1 +\tracking_changes false +\output_changes false +\change_bars false +\postpone_fragile_content false +\html_math_output 0 +\html_css_as_file 0 +\html_be_strict false +\docbook_table_output 0 +\end_header + +\begin_body + +\begin_layout Title +\SpecialChar LyX +' detailliertes Mathe Handbuch +\end_layout + +\begin_layout Section +Grundlegende Funktionen +\end_layout + +\begin_layout Subsection +Fortsetzungspunkte +\end_layout + +\begin_layout Standard +Z. +\begin_inset space \thinspace{} +\end_inset + +B. + ergibt der Befehl +\series bold +A +\backslash +dotfill +\begin_inset space \textvisiblespace{} +\end_inset + +B +\end_layout + +\begin_layout Standard +\begin_inset Formula $A\dotfill B$ +\end_inset + + +\end_layout + +\begin_layout Standard +Analog dazu gibt es für eine Linie den Befehl +\series bold + +\backslash +hrulefill +\series default + +\begin_inset Index idx +status collapsed + +\begin_layout Plain Layout +Befehle ! H ! +\backslash +hrulefill +\end_layout + +\end_inset + +: +\end_layout + +\begin_layout Standard +\begin_inset Formula $A\hrulefill B$ +\end_inset + + +\end_layout + +\begin_layout Standard +Um die Befehle für Text zu verwenden, müssen sie im \SpecialChar TeX +-Modus eingegeben werden. +\end_layout + +\end_body +\end_document diff --git a/autotests/export/docbook/doc_de_Math.xml b/autotests/export/docbook/doc_de_Math.xml new file mode 100644 index 0000000000..5f4a24065e --- /dev/null +++ b/autotests/export/docbook/doc_de_Math.xml @@ -0,0 +1,23 @@ + + +
+LyX' detailliertes Mathe Handbuch +
+Grundlegende Funktionen +
+Fortsetzungspunkte +Z. B. ergibt der Befehl A\dotfill␣B + +A\dotfill B +MathML export failed. Please report this as a bug. + +Analog dazu gibt es für eine Linie den Befehl \hrulefillBefehleH\textbackslash hrulefill: + +A\hrulefill B +MathML export failed. Please report this as a bug. + +Um die Befehle für Text zu verwenden, müssen sie im TeX-Modus eingegeben werden. +
+
+
\ No newline at end of file diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp index 458d8389c0..077c304874 100644 --- a/src/output_docbook.cpp +++ b/src/output_docbook.cpp @@ -27,6 +27,7 @@ #include "insets/InsetBibtex.h" #include "insets/InsetBibitem.h" #include "insets/InsetLabel.h" +#include "mathed/InsetMath.h" #include "insets/InsetNote.h" #include "support/lassert.h" @@ -447,8 +448,9 @@ void makeParagraph( // Plain layouts must be ignored. special_case |= buf.params().documentClass().isPlainLayout(par->layout()) && !runparams.docbook_force_pars; // Equations do not deserve their own paragraph (DocBook allows them outside paragraphs). + // Exception: any case that generates an must still get a paragraph to be valid. special_case |= nInsets == (size_t) par->size() && std::all_of(par->insetList().begin(), par->insetList().end(), [](InsetList::Element inset) { - return inset.inset && inset.inset->asInsetMath(); + return inset.inset && inset.inset->asInsetMath() && inset.inset->asInsetMath()->getType() != hullSimple; }); // TODO: Could get rid of this with a DocBook equivalent to htmlisblock? Not for all cases, unfortunately... See above for those that have been determined not to be allowable for this potential refactoring.