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

👩‍💻 Allow index entries on many more node types for myst-to-tex #1524

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/unlucky-timers-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'myst-to-tex': patch
---

Allow index entries on many more nodes for myst-to-tex
8 changes: 8 additions & 0 deletions packages/myst-to-tex/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const handlers: Record<string, Handler> = {
state.text(node.value);
},
paragraph(node, state) {
addIndexEntries(node, state);
state.renderChildren(node);
},
heading(node: Heading, state) {
Expand Down Expand Up @@ -177,9 +178,11 @@ const handlers: Record<string, Handler> = {
state.write('\\printindex\n');
return;
}
addIndexEntries(node, state);
state.renderChildren(node, false);
},
blockquote(node, state) {
addIndexEntries(node, state);
state.renderEnvironment(node, 'quote');
},
definitionList(node, state) {
Expand All @@ -202,6 +205,7 @@ const handlers: Record<string, Handler> = {
if (node.visibility === 'remove') {
return;
}
addIndexEntries(node, state);
let start = '\\begin{verbatim}\n';
let end = '\n\\end{verbatim}';

Expand All @@ -223,6 +227,7 @@ const handlers: Record<string, Handler> = {
state.closeBlock(node);
},
list(node, state) {
addIndexEntries(node, state);
if (state.data.isInTable) {
node.children.forEach((child: any, i: number) => {
state.write(node.ordered ? `${i}.~~` : '\\textbullet~~');
Expand Down Expand Up @@ -253,6 +258,7 @@ const handlers: Record<string, Handler> = {
state.renderChildren(node, false);
},
div(node, state) {
addIndexEntries(node, state);
state.renderChildren(node, false);
},
span(node, state) {
Expand Down Expand Up @@ -341,6 +347,7 @@ const handlers: Record<string, Handler> = {
state.write('}');
},
admonition(node, state) {
addIndexEntries(node, state);
state.usePackages('framed');
state.renderEnvironment(node, 'framed');
},
Expand All @@ -350,6 +357,7 @@ const handlers: Record<string, Handler> = {
},
table: renderNodeToLatex,
image(node, state) {
addIndexEntries(node, state);
state.usePackages('graphicx');
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { width: nodeWidth, url: nodeSrc, align: nodeAlign } = node;
Expand Down
2 changes: 2 additions & 0 deletions packages/myst-to-tex/src/math.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Handler, ITexSerializer, SimplifiedMathPlugins } from './types.js';
import { addIndexEntries } from './utils.js';

// Top level environments in amsmath version 2.1 (and eqnarray), see:
// http://anorien.csc.warwick.ac.uk/mirrors/CTAN/macros/latex/required/amsmath/amsldoc.pdf
Expand Down Expand Up @@ -82,6 +83,7 @@ const math: Handler = (node, state) => {
}
state.usePackages('amsmath');
addMacrosToState(node.value, state);
addIndexEntries(node, state);
if (state.data.isInTable) {
state.write('\\(\\displaystyle ');
state.write(node.value);
Expand Down
3 changes: 2 additions & 1 deletion packages/myst-to-tex/src/proof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { ProofContainer, ProofKind } from 'myst-ext-proof';
import { select } from 'unist-util-select';
import { remove } from 'unist-util-remove';
import type { Handler } from './types.js';
import { addIndexEntries } from './utils.js';

function kindToEnvironment(kind: ProofKind): string {
switch (kind) {
Expand Down Expand Up @@ -55,7 +56,7 @@ export const proofHandler: Handler = (node, state) => {
t.type = '__delete__';
}
const newNode = remove(node, '__delete__') as GenericNode;

addIndexEntries(node, state);
state.write('\\begin{');
state.write(env);
state.write('}');
Expand Down
2 changes: 2 additions & 0 deletions packages/myst-to-tex/src/tables.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Table, TableRow, TableCell as SpecTableCell } from 'myst-spec';
import type { ITexSerializer } from './types.js';
import { addIndexEntries } from './utils.js';

export const TOTAL_TABLE_WIDTH = 886;

Expand Down Expand Up @@ -101,6 +102,7 @@ export function renderNodeToLatex(node: Table, state: ITexSerializer) {
if (!numColumns) {
throw new Error('invalid table format, no columns');
}
addIndexEntries(node, state);
state.data.isInTable = true; // this is cleared at the end of this function
if (!state.data.isInContainer) {
state.write('\\bigskip\\noindent');
Expand Down
Loading