Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use same cmd for build and preview #3978

Merged
merged 11 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 46 additions & 14 deletions src/buildmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ void BuildManager::registerOptions(ConfigManagerInterface &cmi)
cmi.registerOption("Tools/Quick Mode", &deprecatedQuickmode, -1);
cmi.registerOption("Tools/Max Expanding Nesting Deep", &maxExpandingNestingDeep, 10);
Q_ASSERT(sizeof(dvi2pngMode) == sizeof(int));
cmi.registerOption("Tools/Dvi2Png Mode", reinterpret_cast<int *>(&dvi2pngMode), 3);
cmi.registerOption("Tools/Dvi2Png Mode", reinterpret_cast<int *>(&dvi2pngMode), static_cast<int>(DPM_BUILD_COMPILER));
cmi.registerOption("Files/Save Files Before Compiling", reinterpret_cast<int *>(&saveFilesBeforeCompiling), static_cast<int>(SFBC_ONLY_NAMED));
cmi.registerOption("Preview/Remove Beamer Class", &previewRemoveBeamer, true);
cmi.registerOption("Preview/Precompile Preamble", &previewPrecompilePreamble, true);
Expand Down Expand Up @@ -1453,7 +1453,7 @@ void BuildManager::readSettings(QSettings &settings)

int md = dvi2pngMode;
#ifdef NO_POPPLER_PREVIEW
if (md == DPM_EMBEDDED_PDF || md == DPM_LUA_EMBEDDED_PDF || md == DPM_XE_EMBEDDED_PDF)
if (modifyHeader.contains(static_cast<Dvi2PngMode>(md)))
md = -1;
#endif
if (md < 0) {
Expand Down Expand Up @@ -1771,6 +1771,36 @@ void addLaTeXInputPaths(ProcessX *p, const QStringList &paths)
p->setOverrideEnvironment(env);
}

/*!
* \brief find a Preview Mode which uses the Build Compiler (Default or by Magic Comment)
* It was reported (#3851) that external storage was filled up when running a preview with a different compiler than the Build Compiler from the
* Build setup. To prevent this use "Default Compiler as set up in Build config" (DPM_BUILD_COMPILER) from combobox. This is also useful when you
* switch between documents which can't be compiled with the same compiler and a manual switch would also be necessary for previews.
*/
BuildManager::Dvi2PngMode BuildManager::guessDvi2PngMode() {
Dvi2PngMode dvi2pngModeDerived = DPM_DVIPNG;
if (dvi2pngMode==DPM_BUILD_COMPILER) {
bool user;
QString compiler;
emit commandLineRequested("compile", &compiler, &user);
if (!user) {
if (isCommandDirectlyDefined(compiler)) {
if (compiler==CMD_PDFLATEX)
dvi2pngModeDerived = DPM_EMBEDDED_PDF;
else if (compiler==CMD_LUALATEX)
dvi2pngModeDerived = DPM_LUA_EMBEDDED_PDF;
else if (compiler==CMD_XELATEX)
dvi2pngModeDerived = DPM_XE_EMBEDDED_PDF;
else if (compiler==CMD_LATEX)
dvi2pngModeDerived = DPM_DVIPNG;
}
}
}
else dvi2pngModeDerived = dvi2pngMode;

return dvi2pngModeDerived;
}

//there are 3 ways to generate a preview png:
//1. latex is called => dvipng is called after latex finished and converts the dvi
//2. latex is called and dvipng --follow is called at the same time, and will manage the wait time on its own
Expand All @@ -1779,6 +1809,7 @@ void addLaTeXInputPaths(ProcessX *p, const QStringList &paths)
void BuildManager::preview(const QString &preamble, const PreviewSource &source, const QString &masterFile, QTextCodec *outputCodec)
{
QString tempPath = QDir::tempPath() + QDir::separator() + "." + QDir::separator();
Dvi2PngMode dvi2pngModeDerived = guessDvi2PngMode();

//process preamble
QString preamble_mod = preamble;
Expand Down Expand Up @@ -1832,11 +1863,11 @@ void BuildManager::preview(const QString &preamble, const PreviewSource &source,
preambleFormatFile = fi.completeBaseName();
previewFileNames.append(fi.absoluteFilePath());
ProcessX *p = nullptr;
if (dvi2pngMode == DPM_EMBEDDED_PDF) {
if (dvi2pngModeDerived == DPM_EMBEDDED_PDF) {
p = newProcessInternal(QString("%1 -interaction=nonstopmode -ini \"&pdflatex %2 \\dump\"").arg(getCommandInfo(CMD_PDFLATEX).getProgramName(),preambleFormatFile), QFileInfo(tf->fileName())); //no delete! goes automatically
} else if (dvi2pngMode == DPM_LUA_EMBEDDED_PDF) {
} else if (dvi2pngModeDerived == DPM_LUA_EMBEDDED_PDF) {
p = newProcessInternal(QString("%1 -interaction=nonstopmode -ini \"&lualatex %2 \\dump\"").arg(getCommandInfo(CMD_LUALATEX).getProgramName(),preambleFormatFile), QFileInfo(tf->fileName())); //no delete! goes automatically
} else if (dvi2pngMode == DPM_XE_EMBEDDED_PDF) {
} else if (dvi2pngModeDerived == DPM_XE_EMBEDDED_PDF) {
p = newProcessInternal(QString("%1 -interaction=nonstopmode -ini \"&xelatex %2 \\dump\"").arg(getCommandInfo(CMD_XELATEX).getProgramName(),preambleFormatFile), QFileInfo(tf->fileName())); //no delete! goes automatically
} else {
p = newProcessInternal(QString("%1 -interaction=nonstopmode -ini \"&latex %2 \\dump\"").arg(getCommandInfo(CMD_LATEX).getProgramName(),preambleFormatFile), QFileInfo(tf->fileName())); //no delete! goes automatically
Expand Down Expand Up @@ -1894,11 +1925,11 @@ void BuildManager::preview(const QString &preamble, const PreviewSource &source,
tf->close();
delete tf; // tex file needs to be freed
ProcessX *p1 = nullptr;
if (dvi2pngMode == DPM_EMBEDDED_PDF) {
if (dvi2pngModeDerived == DPM_EMBEDDED_PDF) {
// start conversion
// tex -> pdf
p1 = firstProcessOfDirectExpansion(CMD_PDFLATEX, QFileInfo(ffn)); //no delete! goes automatically
} else if (dvi2pngMode == DPM_LUA_EMBEDDED_PDF) {
} else if (dvi2pngModeDerived == DPM_LUA_EMBEDDED_PDF) {
// start conversion
// tex -> pdf
QString command = getCommandInfo(CMD_LUALATEX).commandLine;
Expand All @@ -1907,7 +1938,7 @@ void BuildManager::preview(const QString &preamble, const PreviewSource &source,
command = command.insert(pgm.length(), " -fmt=" + preambleFormatFile);
}
p1 = firstProcessOfDirectExpansion(command, QFileInfo(ffn)); //no delete! goes automatically
} else if (dvi2pngMode == DPM_XE_EMBEDDED_PDF) {
} else if (dvi2pngModeDerived == DPM_XE_EMBEDDED_PDF) {
// start conversion
// tex -> pdf
QString command = getCommandInfo(CMD_XELATEX).commandLine;
Expand All @@ -1927,7 +1958,7 @@ void BuildManager::preview(const QString &preamble, const PreviewSource &source,
p1->startCommand();
QTimer::singleShot(previewCompileTimeOut, p1, SLOT(kill()));

if (dvi2pngMode == DPM_DVIPNG_FOLLOW) {
if (dvi2pngModeDerived == DPM_DVIPNG_FOLLOW) {
p1->waitForStarted();
// dvi -> png
//follow mode is a tricky features which allows dvipng to run while tex isn't finished
Expand Down Expand Up @@ -2097,7 +2128,8 @@ void BuildManager::latexPreviewCompleted(int status)
if(status>0){
return; // compilation has failed
}
if (dvi2pngMode == DPM_DVIPNG) {
Dvi2PngMode dvi2pngModeDerived = guessDvi2PngMode();
if (dvi2pngModeDerived == DPM_DVIPNG) {
ProcessX *p1 = qobject_cast<ProcessX *> (sender());
if (!p1) return;
// dvi -> png
Expand All @@ -2108,7 +2140,7 @@ void BuildManager::latexPreviewCompleted(int status)
connect(p2, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(conversionPreviewCompleted(int)));
p2->startCommand();
}
if (dvi2pngMode == DPM_DVIPS_GHOSTSCRIPT) {
if (dvi2pngModeDerived == DPM_DVIPS_GHOSTSCRIPT) {
ProcessX *p1 = qobject_cast<ProcessX *> (sender());
if (!p1) return;
// dvi -> ps
Expand All @@ -2119,7 +2151,7 @@ void BuildManager::latexPreviewCompleted(int status)
connect(p2, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(dvi2psPreviewCompleted(int)));
p2->startCommand();
}
if (dvi2pngMode == DPM_EMBEDDED_PDF) {
if (dvi2pngModeDerived == DPM_EMBEDDED_PDF) {
ProcessX *p1 = qobject_cast<ProcessX *> (sender());
if (!p1) return;
QString processedFile = p1->getFile();
Expand All @@ -2133,7 +2165,7 @@ void BuildManager::latexPreviewCompleted(int status)
emit previewAvailable(fn, previewFileNameToSource[processedFile]);
}
}
if (dvi2pngMode == DPM_LUA_EMBEDDED_PDF) {
if (dvi2pngModeDerived == DPM_LUA_EMBEDDED_PDF) {
ProcessX *p1 = qobject_cast<ProcessX *> (sender());
if (!p1) return;
QString processedFile = p1->getFile();
Expand All @@ -2147,7 +2179,7 @@ void BuildManager::latexPreviewCompleted(int status)
emit previewAvailable(fn, previewFileNameToSource[processedFile]);
}
}
if (dvi2pngMode == DPM_XE_EMBEDDED_PDF) {
if (dvi2pngModeDerived == DPM_XE_EMBEDDED_PDF) {
ProcessX *p1 = qobject_cast<ProcessX *> (sender());
if (!p1) return;
QString processedFile = p1->getFile();
Expand Down
5 changes: 4 additions & 1 deletion src/buildmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,11 @@ public slots:
int deprecatedQuickmode;
QStringList deprecatedUserToolCommands, deprecatedUserToolNames;
QStringList userToolOrder, userToolDisplayNames;
enum Dvi2PngMode { DPM_DVIPNG, DPM_DVIPNG_FOLLOW, DPM_DVIPS_GHOSTSCRIPT, DPM_EMBEDDED_PDF, DPM_LUA_EMBEDDED_PDF, DPM_XE_EMBEDDED_PDF};
enum Dvi2PngMode { DPM_DVIPNG, DPM_DVIPNG_FOLLOW, DPM_DVIPS_GHOSTSCRIPT, DPM_EMBEDDED_PDF, DPM_LUA_EMBEDDED_PDF, DPM_XE_EMBEDDED_PDF, DPM_BUILD_COMPILER};

Dvi2PngMode dvi2pngMode;
BuildManager::Dvi2PngMode guessDvi2PngMode();

enum SaveFilesBeforeCompiling {SFBC_ALWAYS, SFBC_ONLY_CURRENT_OR_NAMED, SFBC_ONLY_NAMED};
SaveFilesBeforeCompiling saveFilesBeforeCompiling;
bool previewRemoveBeamer, previewPrecompilePreamble;
Expand Down
13 changes: 3 additions & 10 deletions src/configdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ ConfigDialog::ConfigDialog(QWidget *parent): QDialog(parent,Qt::Dialog|Qt::Windo
connect(UpdateChecker::instance(), SIGNAL(checkCompleted()), this, SLOT(refreshLastUpdateTime()));
refreshLastUpdateTime();

//pageditor
//pageEditor
populateComboBoxFont(false);
connect(ui.checkBoxShowOnlyMonospacedFonts, SIGNAL(toggled(bool)), this, SLOT(populateComboBoxFont(bool)));

Expand Down Expand Up @@ -489,7 +489,8 @@ ConfigDialog::ConfigDialog(QWidget *parent): QDialog(parent,Qt::Dialog|Qt::Windo
.arg("<a href=\"https://extensions.openoffice.org/de/search?f[0]=field_project_tags%3A157\">OpenOffice</a>",
"<a href=\"https://extensions.libreoffice.org/?Tag%5B0%5D=50&q=&Tags%5B%5D=50\">LibreOffice</a>"));
ui.labelGetDic->setOpenExternalLinks(true);
//pagequick

//pageQuick
connect(ui.pushButtonGrammarWordlists, SIGNAL(clicked()), this, SLOT(browseGrammarWordListsDir()));
connect(ui.pushButtonGrammarLTPath, SIGNAL(clicked()), this, SLOT(browseGrammarLTPath()));
connect(ui.pushButtonGrammarLTJava, SIGNAL(clicked()), this, SLOT(browseGrammarLTJavaPath()));
Expand Down Expand Up @@ -591,14 +592,6 @@ ConfigDialog::ConfigDialog(QWidget *parent): QDialog(parent,Qt::Dialog|Qt::Windo
ui.lineEditMetaFilter->setPlaceholderText(tr("(option filter)"));
connect(ui.lineEditMetaFilter, SIGNAL(textChanged(QString)), SLOT(metaFilterChanged(QString)));

// poppler preview
#ifdef NO_POPPLER_PREVIEW
int l = ui.comboBoxDvi2PngMode->count();
ui.comboBoxDvi2PngMode->removeItem(l - 1);
l = ui.comboBoxPreviewMode->count();
ui.comboBoxPreviewMode->removeItem(l - 1);
// maybe add some possibility to disable some preview modes in poppler mode
#endif
ui.labelScreenResolution->setText(labelSystemdpi);

// set-up GUI scaling
Expand Down
87 changes: 46 additions & 41 deletions src/configdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -4002,18 +4002,23 @@ them here.</string>
<string>Preview</string>
</property>
<layout class="QGridLayout" name="gridLayout_5" columnstretch="0,1">
<item row="0" column="0">
<item row="1" column="0">
<widget class="QLabel" name="label_31">
<property name="text">
<string>Command:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<item row="1" column="1">
<widget class="QComboBox" name="comboBoxDvi2PngMode">
<property name="advancedOption" stdset="0">
<bool>false</bool>
</property>
<item>
<property name="text">
<string>Default Compiler as set up in Build configuration</string>
</property>
</item>
<item>
<property name="text">
<string>Preview with dvipng</string>
Expand Down Expand Up @@ -4046,7 +4051,7 @@ them here.</string>
</item>
</widget>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="label_32">
<property name="text">
<string>Display Mode:</string>
Expand All @@ -4056,7 +4061,7 @@ them here.</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QComboBox" name="comboBoxPreviewMode">
<property name="toolTip">
<string>When the mode is changed, the preview on formulas is displayed accordingly (but for Inline it's still a tooltip).</string>
Expand Down Expand Up @@ -4097,6 +4102,38 @@ them here.</string>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_75">
<property name="toolTip">
<string/>
</property>
<property name="text">
<string>Scaling:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="spinBoxSegmentPreviewScalePercent">
<property name="toolTip">
<string/>
</property>
<property name="specialValueText">
<string notr="true"/>
</property>
<property name="suffix">
<string>%</string>
</property>
<property name="minimum">
<number>20</number>
</property>
<property name="maximum">
<number>10000</number>
</property>
<property name="singleStep">
<number>10</number>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_35">
<property name="toolTip">
<string>Update the preview on text change</string>
Expand All @@ -4106,7 +4143,7 @@ them here.</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<widget class="QComboBox" name="comboBoxAutoPreview">
<item>
<property name="text">
Expand All @@ -4120,7 +4157,7 @@ them here.</string>
</item>
</widget>
</item>
<item row="4" column="0">
<item row="5" column="0">
<widget class="QLabel" name="label_36">
<property name="text">
<string>Auto Update Delay:</string>
Expand All @@ -4130,7 +4167,7 @@ them here.</string>
</property>
</widget>
</item>
<item row="4" column="1">
<item row="5" column="1">
<widget class="QSpinBox" name="spinBoxAutoPreviewDelay">
<property name="suffix">
<string> ms</string>
Expand All @@ -4146,7 +4183,7 @@ them here.</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxReplaceBeamer">
<property name="text">
<string>Replace beamer class by article</string>
Expand All @@ -4159,7 +4196,7 @@ them here.</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<item row="7" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxPrecompilePreamble">
<property name="text">
<string>Precompile Preamble</string>
Expand All @@ -4172,38 +4209,6 @@ them here.</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_75">
<property name="toolTip">
<string/>
</property>
<property name="text">
<string>Scaling:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="spinBoxSegmentPreviewScalePercent">
<property name="toolTip">
<string/>
</property>
<property name="specialValueText">
<string notr="true"/>
</property>
<property name="suffix">
<string>%</string>
</property>
<property name="minimum">
<number>20</number>
</property>
<property name="maximum">
<number>10000</number>
</property>
<property name="singleStep">
<number>10</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
Loading
Loading