From 4d03d91aec0373b7a5f635b240675f774e4b53c4 Mon Sep 17 00:00:00 2001 From: markusritschel Date: Thu, 11 Apr 2024 15:36:26 +0200 Subject: [PATCH 1/7] Replace latexmk with tectonic https://tectonic-typesetting.github.io/ --- packages/jtex/src/tex/export.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/jtex/src/tex/export.ts b/packages/jtex/src/tex/export.ts index a981930c7..90fac8e78 100644 --- a/packages/jtex/src/tex/export.ts +++ b/packages/jtex/src/tex/export.ts @@ -8,9 +8,7 @@ export function pdfTexExportCommand( template?: MystTemplate, ): string { const templateYml = template?.getValidatedTemplateYml(); - const engine = templateYml?.build?.engine ?? '-xelatex'; - const baseCommand = `latexmk -f ${engine} -synctex=1 -interaction=batchmode -file-line-error -latexoption="-shell-escape" ${texFile}`; - + const baseCommand = `tectonic -X compile --keep-intermediates --keep-logs ${texFile}`; return createCommand(baseCommand, logFile); } From 3537822cd98fe2664eff8352be24df376df136ca Mon Sep 17 00:00:00 2001 From: markusritschel Date: Thu, 11 Apr 2024 15:39:00 +0200 Subject: [PATCH 2/7] Add tectonic availability check and modify warning if no build tool available --- packages/myst-cli/src/build/pdf/create.ts | 6 +++--- packages/myst-cli/src/build/pdf/utils.ts | 4 ++++ packages/myst-cli/src/docs.ts | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/myst-cli/src/build/pdf/create.ts b/packages/myst-cli/src/build/pdf/create.ts index bfdcd11d8..93b8ffc41 100644 --- a/packages/myst-cli/src/build/pdf/create.ts +++ b/packages/myst-cli/src/build/pdf/create.ts @@ -14,7 +14,7 @@ import { uniqueArray } from '../../utils/uniqueArray.js'; import { logMessagesFromVFile } from '../../utils/logging.js'; import { createTempFolder } from '../../utils/createTempFolder.js'; import { cleanOutput } from '../utils/cleanOutput.js'; -import { isLatexmkAvailable, isMakeglossariesAvailable } from './utils.js'; +import { isTectonicAvailable, isLatexmkAvailable, isMakeglossariesAvailable } from './utils.js'; const copyFile = util.promisify(fs.copyFile); @@ -263,10 +263,10 @@ async function runPdfBuildCommand( vfile: VFile, debugLogsOnly?: boolean, ) { - if (!isLatexmkAvailable()) { + if (!(isTectonicAvailable() || isLatexmkAvailable())) { fileError( vfile, - `⚠️ The "latexmk" command is not available. See documentation on installing LaTeX:\n\n${docLinks.installLatex}`, + `⚠️ Neither "tectonic" nor "latexmk" command is available. See documentation on installing LaTeX:\n\n${docLinks.installLatex}\n${docLinks.installTectonic}`, { ruleId: RuleId.pdfBuildCommandsAvailable }, ); } diff --git a/packages/myst-cli/src/build/pdf/utils.ts b/packages/myst-cli/src/build/pdf/utils.ts index 2dbc3c999..7075d888b 100644 --- a/packages/myst-cli/src/build/pdf/utils.ts +++ b/packages/myst-cli/src/build/pdf/utils.ts @@ -6,6 +6,10 @@ export function isLatexmkAvailable() { return which.sync('latexmk', { nothrow: true }); } +export function isTectonicAvailable() { + return which.sync('tectonic', { nothrow: true }); +} + export function isMakeglossariesAvailable() { return which.sync('makeglossaries', { nothrow: true }); } diff --git a/packages/myst-cli/src/docs.ts b/packages/myst-cli/src/docs.ts index cb6124e6c..ab70ca118 100644 --- a/packages/myst-cli/src/docs.ts +++ b/packages/myst-cli/src/docs.ts @@ -1,4 +1,5 @@ export const docLinks = { installNode: 'https://nodejs.org/en/download/', installLatex: 'https://mystmd.org/guide/creating-pdf-documents#install-latex', + installTectonic: 'https://tectonic-typesetting.github.io/en-US/install.html', }; From 6c0f3cf47b1772eae615f74e1394eba0f70321b9 Mon Sep 17 00:00:00 2001 From: markusritschel Date: Thu, 11 Apr 2024 15:43:44 +0200 Subject: [PATCH 3/7] Add `latexmk` as fallback Currently, I cannot import isLatexmkAvailable and isTectonicAvailable from '../../../myst-cli/src/build/pdf/utils.ts'. I am therefore duplicating the two functions in jtex/src/tex/exports. See also: https://github.com/orgs/executablebooks/discussions/1154#discussioncomment-9084375. Hopefully this can be modified later. --- packages/jtex/src/tex/export.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/jtex/src/tex/export.ts b/packages/jtex/src/tex/export.ts index 90fac8e78..5222aaece 100644 --- a/packages/jtex/src/tex/export.ts +++ b/packages/jtex/src/tex/export.ts @@ -1,6 +1,15 @@ import path from 'node:path'; import type MystTemplate from 'myst-templates'; import { createCommand } from '../utils.js'; +import which from 'which'; + +export function isLatexmkAvailable() { + return which.sync('latexmk', { nothrow: true }); +} + +export function isTectonicAvailable() { + return which.sync('tectonic', { nothrow: true }); +} export function pdfTexExportCommand( texFile: string, @@ -8,7 +17,13 @@ export function pdfTexExportCommand( template?: MystTemplate, ): string { const templateYml = template?.getValidatedTemplateYml(); - const baseCommand = `tectonic -X compile --keep-intermediates --keep-logs ${texFile}`; + // Use Tectonic by default (https://tectonic-typesetting.github.io) + let baseCommand = `tectonic -X compile --keep-intermediates --keep-logs ${texFile}`; + // Alternatively, switch to Latexmk with xelatex + if (!isTectonicAvailable() && isLatexmkAvailable()) { + const engine = templateYml?.build?.engine ?? '-xelatex'; + baseCommand = `latexmk -f ${engine} -synctex=1 -interaction=batchmode -file-line-error -latexoption="-shell-escape" ${texFile}`; + } return createCommand(baseCommand, logFile); } From 6c7340cc60604e116106964154ea83cead72fba8 Mon Sep 17 00:00:00 2001 From: Markus Ritschel Date: Thu, 11 Apr 2024 16:54:47 +0200 Subject: [PATCH 4/7] Add tectonic paragraph in documentation --- docs/creating-pdf-documents.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/creating-pdf-documents.md b/docs/creating-pdf-documents.md index 47e4b30d9..78dbc8b68 100644 --- a/docs/creating-pdf-documents.md +++ b/docs/creating-pdf-documents.md @@ -87,6 +87,12 @@ See the official documentation for installation instructions for $\LaTeX$ at: Ensure that you download a full distribution with appropriate libraries installed. +(install-tectonic)= + +#### Tectonic as a lightweight alternative +As an alternative, you can also install [Tectonic](https://tectonic-typesetting.github.io/), "a modernized, complete, self-contained TeX/LaTeX engine, powered by XeTeX and TeXLive".
+> "Tectonic automatically downloads support files so you don’t have to install a full LaTeX system in order to start using it. If you start using a new LaTeX package, Tectonic just pulls down the files it needs and continues processing." (excerpt from the website) + % Probably a note in the future about running this remotely? (rendering-pdfs-with-typst)= From 5fec6ca34601760c6ac040bca7e183224e6c31df Mon Sep 17 00:00:00 2001 From: Markus Ritschel Date: Thu, 11 Apr 2024 16:55:20 +0200 Subject: [PATCH 5/7] Let installTectonic link point to section in documentation --- packages/myst-cli/src/docs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/myst-cli/src/docs.ts b/packages/myst-cli/src/docs.ts index ab70ca118..a177569b3 100644 --- a/packages/myst-cli/src/docs.ts +++ b/packages/myst-cli/src/docs.ts @@ -1,5 +1,5 @@ export const docLinks = { installNode: 'https://nodejs.org/en/download/', installLatex: 'https://mystmd.org/guide/creating-pdf-documents#install-latex', - installTectonic: 'https://tectonic-typesetting.github.io/en-US/install.html', + installTectonic: 'https://mystmd.org/guide/creating-pdf-documents#install-tectonic' }; From 05260993a078804c093df7d9da4ef7ed8cf6f794 Mon Sep 17 00:00:00 2001 From: Markus Ritschel Date: Thu, 11 Apr 2024 17:04:49 +0200 Subject: [PATCH 6/7] Update docs/creating-pdf-documents.md Co-authored-by: Rowan Cockett --- docs/creating-pdf-documents.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/creating-pdf-documents.md b/docs/creating-pdf-documents.md index 78dbc8b68..2f9911060 100644 --- a/docs/creating-pdf-documents.md +++ b/docs/creating-pdf-documents.md @@ -91,7 +91,9 @@ Ensure that you download a full distribution with appropriate libraries installe #### Tectonic as a lightweight alternative As an alternative, you can also install [Tectonic](https://tectonic-typesetting.github.io/), "a modernized, complete, self-contained TeX/LaTeX engine, powered by XeTeX and TeXLive".
-> "Tectonic automatically downloads support files so you don’t have to install a full LaTeX system in order to start using it. If you start using a new LaTeX package, Tectonic just pulls down the files it needs and continues processing." (excerpt from the website) +> Tectonic automatically downloads support files so you don’t have to install a full LaTeX system in order to start using it. If you start using a new LaTeX package, Tectonic just pulls down the files it needs and continues processing. +> +> -- [Tectonic Website](https://tectonic-typesetting.github.io/) % Probably a note in the future about running this remotely? From 2e4e699b00b6d79521042f0f804434cb86139525 Mon Sep 17 00:00:00 2001 From: Markus Ritschel Date: Thu, 11 Apr 2024 17:12:29 +0200 Subject: [PATCH 7/7] Update docs/creating-pdf-documents.md Co-authored-by: Rowan Cockett --- docs/creating-pdf-documents.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/creating-pdf-documents.md b/docs/creating-pdf-documents.md index 2f9911060..47737f198 100644 --- a/docs/creating-pdf-documents.md +++ b/docs/creating-pdf-documents.md @@ -93,7 +93,7 @@ Ensure that you download a full distribution with appropriate libraries installe As an alternative, you can also install [Tectonic](https://tectonic-typesetting.github.io/), "a modernized, complete, self-contained TeX/LaTeX engine, powered by XeTeX and TeXLive".
> Tectonic automatically downloads support files so you don’t have to install a full LaTeX system in order to start using it. If you start using a new LaTeX package, Tectonic just pulls down the files it needs and continues processing. > -> -- [Tectonic Website](https://tectonic-typesetting.github.io/) +> – [Tectonic Website](https://tectonic-typesetting.github.io/) % Probably a note in the future about running this remotely?