Skip to content

Commit 26e3164

Browse files
committed
preview with xelatex
1 parent 119fead commit 26e3164

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

src/buildmanager.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,7 @@ void BuildManager::readSettings(QSettings &settings)
14281428

14291429
int md = dvi2pngMode;
14301430
#ifdef NO_POPPLER_PREVIEW
1431-
if (md == DPM_EMBEDDED_PDF || md == DPM_LUA_EMBEDDED_PDF)
1431+
if (md == DPM_EMBEDDED_PDF || md == DPM_LUA_EMBEDDED_PDF || md == DPM_XE_EMBEDDED_PDF)
14321432
md = -1;
14331433
#endif
14341434
if (md < 0) {
@@ -1811,6 +1811,8 @@ void BuildManager::preview(const QString &preamble, const PreviewSource &source,
18111811
p = newProcessInternal(QString("%1 -interaction=nonstopmode -ini \"&pdflatex %2 \\dump\"").arg(getCommandInfo(CMD_PDFLATEX).getProgramName(),preambleFormatFile), QFileInfo(tf->fileName())); //no delete! goes automatically
18121812
} else if (dvi2pngMode == DPM_LUA_EMBEDDED_PDF) {
18131813
p = newProcessInternal(QString("%1 -interaction=nonstopmode -ini \"&lualatex %2 \\dump\"").arg(getCommandInfo(CMD_LUALATEX).getProgramName(),preambleFormatFile), QFileInfo(tf->fileName())); //no delete! goes automatically
1814+
} else if (dvi2pngMode == DPM_XE_EMBEDDED_PDF) {
1815+
p = newProcessInternal(QString("%1 -interaction=nonstopmode -ini \"&xelatex %2 \\dump\"").arg(getCommandInfo(CMD_XELATEX).getProgramName(),preambleFormatFile), QFileInfo(tf->fileName())); //no delete! goes automatically
18141816
} else {
18151817
p = newProcessInternal(QString("%1 -interaction=nonstopmode -ini \"&latex %2 \\dump\"").arg(getCommandInfo(CMD_LATEX).getProgramName(),preambleFormatFile), QFileInfo(tf->fileName())); //no delete! goes automatically
18161818
}
@@ -1880,6 +1882,15 @@ void BuildManager::preview(const QString &preamble, const PreviewSource &source,
18801882
command = command.insert(pgm.length(), " -fmt=" + preambleFormatFile);
18811883
}
18821884
p1 = firstProcessOfDirectExpansion(command, QFileInfo(ffn)); //no delete! goes automatically
1885+
} else if (dvi2pngMode == DPM_XE_EMBEDDED_PDF) {
1886+
// start conversion
1887+
// tex -> pdf
1888+
QString command = getCommandInfo(CMD_XELATEX).commandLine;
1889+
if (preambleFormatFile != "") {
1890+
QString pgm = getCommandInfo(CMD_XELATEX).getProgramName();
1891+
command = command.insert(pgm.length(), " -fmt=" + preambleFormatFile);
1892+
}
1893+
p1 = firstProcessOfDirectExpansion(command, QFileInfo(ffn)); //no delete! goes automatically
18831894
} else {
18841895
// start conversion
18851896
// tex -> dvi
@@ -2111,6 +2122,20 @@ void BuildManager::latexPreviewCompleted(int status)
21112122
emit previewAvailable(fn, previewFileNameToSource[processedFile]);
21122123
}
21132124
}
2125+
if (dvi2pngMode == DPM_XE_EMBEDDED_PDF) {
2126+
ProcessX *p1 = qobject_cast<ProcessX *> (sender());
2127+
if (!p1) return;
2128+
QString processedFile = p1->getFile();
2129+
if (processedFile.endsWith(".tex"))
2130+
processedFile = QDir::fromNativeSeparators(parseExtendedCommandLine("?am.tex", QFileInfo(processedFile)).constFirst());
2131+
// TODO: fromNativeSeparators is a workaround to fix bug
2132+
// yields different dir separators depending on the context. This should be fixed (which direction?).
2133+
// Test (on win): switch preview between dvipng and pdflatex
2134+
QString fn = parseExtendedCommandLine("?am).pdf", QFileInfo(processedFile)).constFirst();
2135+
if (QFileInfo::exists(fn)) {
2136+
emit previewAvailable(fn, previewFileNameToSource[processedFile]);
2137+
}
2138+
}
21142139
}
21152140

21162141
//dvi to ps conversion is finished, call ghostscript to make a useable png from it

src/buildmanager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public slots:
180180
int deprecatedQuickmode;
181181
QStringList deprecatedUserToolCommands, deprecatedUserToolNames;
182182
QStringList userToolOrder, userToolDisplayNames;
183-
enum Dvi2PngMode { DPM_DVIPNG, DPM_DVIPNG_FOLLOW, DPM_DVIPS_GHOSTSCRIPT, DPM_EMBEDDED_PDF, DPM_LUA_EMBEDDED_PDF};
183+
enum Dvi2PngMode { DPM_DVIPNG, DPM_DVIPNG_FOLLOW, DPM_DVIPS_GHOSTSCRIPT, DPM_EMBEDDED_PDF, DPM_LUA_EMBEDDED_PDF, DPM_XE_EMBEDDED_PDF};
184184
Dvi2PngMode dvi2pngMode;
185185
enum SaveFilesBeforeCompiling {SFBC_ALWAYS, SFBC_ONLY_CURRENT_OR_NAMED, SFBC_ONLY_NAMED};
186186
SaveFilesBeforeCompiling saveFilesBeforeCompiling;

src/configdialog.ui

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4024,6 +4024,11 @@ them here.</string>
40244024
<string>Preview with lualatex</string>
40254025
</property>
40264026
</item>
4027+
<item>
4028+
<property name="text">
4029+
<string>Preview with xelatex</string>
4030+
</property>
4031+
</item>
40274032
</widget>
40284033
</item>
40294034
<item row="1" column="0">

src/configmanager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1749,7 +1749,7 @@ bool ConfigManager::execConfigDialog(QWidget *parentToDialog)
17491749
previewMode = static_cast<PreviewMode>(confDlg->ui.comboBoxPreviewMode->currentIndex());
17501750
buildManager->dvi2pngMode = static_cast<BuildManager::Dvi2PngMode>(confDlg->ui.comboBoxDvi2PngMode->currentIndex());
17511751
#ifdef NO_POPPLER_PREVIEW
1752-
if (buildManager->dvi2pngMode == BuildManager::DPM_EMBEDDED_PDF || buildManager->dvi2pngMode == BuildManager::DPM_LUA_EMBEDDED_PDF) {
1752+
if (buildManager->dvi2pngMode == BuildManager::DPM_EMBEDDED_PDF || buildManager->dvi2pngMode == BuildManager::DPM_LUA_EMBEDDED_PDF || buildManager->dvi2pngMode == BuildManager::DPM_XE_EMBEDDED_PDF) {
17531753
buildManager->dvi2pngMode = BuildManager::DPM_DVIPNG; //fallback when poppler is not included
17541754
}
17551755
#endif

src/texstudio.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8830,7 +8830,7 @@ void Texstudio::showPreview(const QString &text)
88308830
QStringList header;
88318831
for (int l = 0; l < m_endingLine; l++)
88328832
header << edView->editor->document()->line(l).text();
8833-
if (buildManager.dvi2pngMode == BuildManager::DPM_EMBEDDED_PDF || buildManager.dvi2pngMode == BuildManager::DPM_LUA_EMBEDDED_PDF) {
8833+
if (buildManager.dvi2pngMode == BuildManager::DPM_EMBEDDED_PDF || buildManager.dvi2pngMode == BuildManager::DPM_LUA_EMBEDDED_PDF || buildManager.dvi2pngMode == BuildManager::DPM_XE_EMBEDDED_PDF) {
88348834
header << "\\usepackage[active,tightpage]{preview}"
88358835
<< "\\usepackage{varwidth}"
88368836
<< "\\AtBeginDocument{\\begin{preview}\\begin{varwidth}{\\linewidth}}"
@@ -8930,7 +8930,7 @@ QStringList Texstudio::makePreviewHeader(const LatexDocument *rootDoc)
89308930
header << newLine;
89318931
}
89328932
}
8933-
if ((buildManager.dvi2pngMode == BuildManager::DPM_EMBEDDED_PDF || buildManager.dvi2pngMode == BuildManager::DPM_LUA_EMBEDDED_PDF)
8933+
if ((buildManager.dvi2pngMode == BuildManager::DPM_EMBEDDED_PDF || buildManager.dvi2pngMode == BuildManager::DPM_LUA_EMBEDDED_PDF || buildManager.dvi2pngMode == BuildManager::DPM_XE_EMBEDDED_PDF)
89348934
&& configManager.previewMode != ConfigManager::PM_EMBEDDED) {
89358935
header << "\\usepackage[active,tightpage]{preview}"
89368936
<< "\\usepackage{varwidth}"

0 commit comments

Comments
 (0)