[LyX/2.4.x] Add "needcopiesfrom" converter flag
Juergen Spitzmueller
spitz at lyx.org
Sun Aug 18 16:34:54 UTC 2024
commit b21f104b3721fb778384c06d5e472f6506b93105
Author: Juergen Spitzmueller <spitz at lyx.org>
Date: Sun Aug 18 17:53:51 2024 +0200
Add "needcopiesfrom" converter flag
This is needed to provide ePub and other DocBook-based exports with
the right (renamed) images (fixes #12372)
(cherry picked from commit 03c58420060fef520d74d835bb39e1b1c9fd7c1e)
---
lib/configure.py | 6 +++---
lib/doc/Customization.lyx | 45 ++++++++++++++++++++++++++++++++++++++++++++
lib/doc/de/Customization.lyx | 45 ++++++++++++++++++++++++++++++++++++++++++++
src/Buffer.cpp | 3 ++-
src/Converter.cpp | 22 +++++++++++++++++++++-
src/Converter.h | 9 ++++++++-
6 files changed, 124 insertions(+), 6 deletions(-)
diff --git a/lib/configure.py b/lib/configure.py
index 2674cd58ee..94501f08bf 100644
--- a/lib/configure.py
+++ b/lib/configure.py
@@ -1022,7 +1022,7 @@ def checkConverterEntries():
checkProg('DocBook converter -> PDF (docbook)',
['pandoc -f docbook -t latex --pdf-engine=lualatex --toc -o $$o $$i', # Since Pandoc 2.0
'pandoc -f docbook -t latex --latex-engine=lualatex --toc -o $$o $$i'], # Up to Pandoc 1.19
- rc_entry = [ r'\converter docbook5 pdf9 "%%" ""' ])
+ rc_entry = [ r'\converter docbook5 pdf9 "%%" "needcopiesfrom=docbook5"' ])
#
xpath, xslt_sheet = checkProg('XSLT stylesheets for ePub', ['chunk.xsl'], '', ['/usr/share/xml/docbook/stylesheet/docbook-xsl-ns/epub3'])
if xslt_sheet == 'chunk.xsl':
@@ -1031,9 +1031,9 @@ def checkConverterEntries():
xpath = 'none'
global java
if xsltproc != '':
- addToRC(r'\converter docbook5 epub "$${python} $$s/scripts/docbook2epub.py none none \"' + xsltproc + r'\" ' + xpath + ' $$i $$r $$o" ""')
+ addToRC(r'\converter docbook5 epub "$${python} $$s/scripts/docbook2epub.py none none \"' + xsltproc + r'\" ' + xpath + ' $$i $$r $$o" "needcopiesfrom=docbook5"')
elif java != '':
- addToRC(r'\converter docbook5 epub "$${python} $$s/scripts/docbook2epub.py \"' + java + r'\" none none ' + xpath + ' $$i $$r $$o" ""')
+ addToRC(r'\converter docbook5 epub "$${python} $$s/scripts/docbook2epub.py \"' + java + r'\" none none ' + xpath + ' $$i $$r $$o" "needcopiesfrom=docbook5"')
#
checkProg('a MS Word Office Open XML converter -> LaTeX', ['pandoc -s -f docx -o $$o -t latex $$i'],
rc_entry = [ r'\converter word2 latex "%%" ""' ])
diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx
index 0500d0fce1..ab6369f635 100644
--- a/lib/doc/Customization.lyx
+++ b/lib/doc/Customization.lyx
@@ -2622,6 +2622,51 @@ latex
\begin_inset Flex Code
status collapsed
+\begin_layout Plain Layout
+needcopiesfrom=<format>
+\end_layout
+
+\end_inset
+
+ Some formats (e.
+\begin_inset space \thinspace{}
+\end_inset
+
+g.,
+ DocBook) generate external files with specific names (for instance if math is rendered as graphic),
+ but they are only generated in the working directory if the respective format is the target format.
+ If you have such a format in your conversion chain and need those files in conversion,
+ use this flag with the respective
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+<format>
+\end_layout
+
+\end_inset
+
+ (cf.
+ the DocBook to ePub converter,
+ which uses
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+needcopiesfrom=docbook5
+\end_layout
+
+\end_inset
+
+).
+ The files will then be made available in the temporary directory as soon as the intermediate format has been generated.
+\end_layout
+
+\begin_layout Labeling
+\labelwidthstring 00.00.0000
+\begin_inset Flex Code
+status collapsed
+
\begin_layout Plain Layout
nice
\end_layout
diff --git a/lib/doc/de/Customization.lyx b/lib/doc/de/Customization.lyx
index c19440e180..5a1ff49e5b 100644
--- a/lib/doc/de/Customization.lyx
+++ b/lib/doc/de/Customization.lyx
@@ -2182,6 +2182,51 @@ latex
\begin_inset Flex Code
status collapsed
+\begin_layout Plain Layout
+needcopiesfrom=<Format>
+\end_layout
+
+\end_inset
+
+ Manche Formate (bspw.
+ DocBook) erzeugen externe Dateien mit speziellen Namen (zum Beispiel,
+ wenn mathematische Formeln als Grafiken dargestellt werden),
+ allerdings geschieht dies nur,
+ wenn das Format den Endpunkt der Konversion darstellt,
+ die Dateien landen dann im Arbeitsverzeichnis.
+ Wenn Sie eines dieser Formate als Zwischenformat haben und diese Dateien im Konvertierungsprozess benötigen,
+ verwenden Sie diesen Flag mit dem entsprechenden
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+<Format>
+\end_layout
+
+\end_inset
+
+ (vgl.
+ den Konverter von DocBook nach ePub,
+ der
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+needcopiesfrom=docbook5
+\end_layout
+
+\end_inset
+
+ verwendet).
+ Die Dateien werden dann im temporären Verzeichnis zur Verfügung gestellt,
+ nachdem das Zwischenformat erzeugt wurde.
+\end_layout
+
+\begin_layout Labeling
+\labelwidthstring 00.00.0000
+\begin_inset Flex Code
+status collapsed
+
\begin_layout Plain Layout
nice
\end_layout
diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 994d5476d5..b6fd8a3bc3 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -4615,7 +4615,8 @@ Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir
Converters::RetVal const retval =
converters.convert(this, FileName(filename), tmp_result_file,
FileName(absFileName()), backend_format, format,
- error_list, Converters::none, includeall);
+ error_list, Converters::none, includeall,
+ runparams.exportdata);
if (retval == Converters::KILLED)
return ExportCancel;
bool success = (retval == Converters::SUCCESS);
diff --git a/src/Converter.cpp b/src/Converter.cpp
index 881aac6bd3..41bd8ce1a0 100644
--- a/src/Converter.cpp
+++ b/src/Converter.cpp
@@ -18,6 +18,7 @@
#include "TextClass.h"
#include "Encoding.h"
#include "ErrorList.h"
+#include "Exporter.h"
#include "Format.h"
#include "InsetList.h"
#include "Language.h"
@@ -143,6 +144,8 @@ void Converter::readFlags()
need_auth_ = true;
else if (flag_name == "hyperref-driver")
href_driver_ = flag_value;
+ else if (flag_name == "needcopiesfrom")
+ need_renamed_copies_from_ = flag_value;
}
if (!result_dir_.empty() && result_file_.empty())
result_file_ = "index." + theFormats().extension(to_);
@@ -414,7 +417,8 @@ Converters::RetVal Converters::convert(Buffer const * buffer,
FileName const & from_file, FileName const & to_file,
FileName const & orig_from,
string const & from_format, string const & to_format,
- ErrorList & errorList, int conversionflags, bool includeall)
+ ErrorList & errorList, int conversionflags, bool includeall,
+ shared_ptr<ExportData> exportdata)
{
if (from_format == to_format)
return move(from_format, from_file, to_file, false) ?
@@ -526,6 +530,22 @@ Converters::RetVal Converters::convert(Buffer const * buffer,
FileName outfile = from_file;
for (auto const & edge : edgepath) {
Converter const & conv = converterlist_[edge];
+ // If the converter requires renamed file copies from an involved
+ // converter, handle this here. These copies stay in the tmp dir
+ if (exportdata && conv.need_renamed_copies_from() == conv.from()) {
+ vector<ExportedFile> const extfiles =
+ exportdata->externalFiles(conv.from());
+ CopyStatus status = FORCE;
+ for (ExportedFile const & exp : extfiles) {
+ string const fmt = theFormats().getFormatFromFile(exp.sourceName);
+ FileName expFileName = makeAbsPath(exp.exportName,
+ exp.sourceName.onlyPath().realPath());
+ status = copyFile(fmt, exp.sourceName,
+ expFileName,
+ exp.exportName, status == FORCE,
+ true);
+ }
+ }
bool dummy = conv.To()->dummy() && conv.to() != "program";
if (!dummy) {
LYXERR(Debug::FILES, "Converting from "
diff --git a/src/Converter.h b/src/Converter.h
index 091dbcd394..720990013a 100644
--- a/src/Converter.h
+++ b/src/Converter.h
@@ -15,6 +15,7 @@
#include "Graph.h"
#include "support/trivstring.h"
+#include <memory>
#include <vector>
#include <set>
#include <string>
@@ -26,6 +27,7 @@ namespace support { class FileName; }
class Buffer;
class ErrorList;
+class ExportData;
class Format;
class Formats;
class OutputParams;
@@ -91,6 +93,8 @@ public:
std::string const parselog() const { return parselog_; }
///
std::string const hyperref_driver() const { return href_driver_; }
+ ///
+ std::string const need_renamed_copies_from() const { return need_renamed_copies_from_; }
private:
///
@@ -128,6 +132,8 @@ private:
trivstring parselog_;
/// The hyperref driver
trivstring href_driver_;
+ /// Needs renamed file copies from an intermediate format
+ trivstring need_renamed_copies_from_;
};
@@ -195,7 +201,8 @@ public:
support::FileName const & from_file, support::FileName const & to_file,
support::FileName const & orig_from,
std::string const & from_format, std::string const & to_format,
- ErrorList & errorList, int conversionflags = none, bool includeall = false);
+ ErrorList & errorList, int conversionflags = none, bool includeall = false,
+ std::shared_ptr<ExportData> exportdata = nullptr);
///
void update(Formats const & formats);
///
More information about the lyx-cvs
mailing list