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

🗺 Add tectonic support #1093

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
6 changes: 6 additions & 0 deletions docs/creating-pdf-documents.md
Original file line number Diff line number Diff line change
Expand Up @@ -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".<br>
> "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)
markusritschel marked this conversation as resolved.
Show resolved Hide resolved

% Probably a note in the future about running this remotely?

(rendering-pdfs-with-typst)=
Expand Down
19 changes: 16 additions & 3 deletions packages/jtex/src/tex/export.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
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(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think let's remove the duplication here by moving this command to myst-cli/src/build/pdf.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great.
The only thing regarding the duplicated functions is that I cannot import them from myst-cli/src/build/pdf/utils.ts to jtex/src/tex/export.ts.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking to move the whole file over, but I see that is a bit complex, and we probably want to do it for typst at the same time.

I am happy to come in after and do a quick refactor, I also want to talk to @fwkoch to get a sense check on moving those around.

Have you tested the functionality locally?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it works on my local machine. Cloned the forked repo and followed your contribution guidelines for developers.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic - I will give it a go today or tomorrow and we can get this released early next week. Thanks again for your help in the PR, excited to try out tectonic and stop recommending 5gb downloads ... !

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😄
My pleasure. Yes, it's still relatively unknown, but it's such a step forward for local LaTeX compiling.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the duplication - it would be nice to eliminate... that would mean "creating the command" (currently in jtex) and "invoking the command" (currently in myst-cli) in one single place. Definitely a smaller refactor to move "creation" to myst-cli, but it could also be interesting if part of the scope of jtex was to know how to create and invoke all the various rendering engines. MyST could then just say "jtex, build me a pdf using this template" hmm...

Anyway - the duplication here is relatively minor; I don't think we need to block this PR with a big refactor.

texFile: string,
logFile: string,
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}`;

// 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);
}

Expand Down
6 changes: 3 additions & 3 deletions packages/myst-cli/src/build/pdf/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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 },
);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/myst-cli/src/build/pdf/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down
1 change: 1 addition & 0 deletions packages/myst-cli/src/docs.ts
Original file line number Diff line number Diff line change
@@ -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://mystmd.org/guide/creating-pdf-documents#install-tectonic'
};