CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/lib/api/schema/latex.ts
Views: 687
1
import { z } from "../framework";
2
3
import { DEFAULT_LATEX_COMMAND } from "../latex";
4
5
import { FailedAPIOperationSchema } from "./common";
6
7
// OpenAPI spec
8
//
9
export const LatexInputSchema = z
10
.object({
11
path: z
12
.string()
13
.describe(
14
`Path to a .tex file. If the file doesn't exist, it is created with the
15
given content. Also, if the directory containing path doesn't exist, it
16
is created. If the path starts with \`/tmp\` (e.g.,
17
\`/tmp/foo/bar.tex\`), then we do always do \`rm /tmp/foo/bar.*\` to
18
clean up temporary files. We do _not_ do this unless the path starts
19
with \`/tmp\`.`,
20
),
21
content: z
22
.string()
23
.optional()
24
.describe(
25
`Textual content of the .tex file on which you want to run LaTeX. If
26
not given, path must refer to an actual file already in the project.
27
Then the path \`.tex\` file is created and this content written to it.`,
28
),
29
project_id: z
30
.string()
31
.uuid()
32
.optional()
33
.describe(
34
`The v4 uuid of a project you have access to. If not given, your most
35
recent project is used, or if you have no projects, one is created. The
36
project is started if it isn't already running. **WARNING:** if the
37
project isn't running you may get an error while it is starting; if you
38
retry in a few seconds then it works.`,
39
),
40
command: z
41
.string()
42
.optional()
43
.describe(
44
`LaTeX build command. This will be run from the directory containing
45
path and should produce the output pdf file. If not given, we use
46
\`${DEFAULT_LATEX_COMMAND} filename.tex\`.`,
47
),
48
timeout: z
49
.number()
50
.gte(5)
51
.default(30)
52
.describe(
53
`If given, this is a timeout in seconds for how long the LaTeX build
54
command can run before it is killed. You should increase this from the
55
default if you're building large documents. See also the
56
\`only_read_pdf\` option.`,
57
),
58
ttl: z
59
.number()
60
.gte(60)
61
.describe("Time in seconds for which generated PDF url is valid.")
62
.default(3600),
63
only_read_pdf: z
64
.boolean()
65
.optional()
66
.describe( `Instead of running LaTeX, we **only** try to grab the output pdf if it
67
exists. Currently, you must also specify the \`project_id\` if you use
68
this option, since we haven't implemented a way to know in which project
69
the latex command was run. When true, \`only_read_pdf\` is the same as
70
when it is false, except only the step involving reading the pdf
71
happens. Use this if compiling times out for some reason due to network
72
timeout requirements. **NOTE:** \`only_read_pdf\` doesn't currently
73
get the compilation output log.`,
74
),
75
})
76
.describe(
77
`Turn LaTeX .tex file contents into a pdf. This run in a CoCalc project
78
with a configurable timeout and command, so can involve arbitrarily
79
sophisticated processing.`,
80
)
81
82
export const LatexOutputSchema = z.union([
83
FailedAPIOperationSchema,
84
z.object({
85
compile: z.object({
86
stdout: z.string(),
87
stderr: z.string(),
88
exit_code: z.number(),
89
}),
90
url: z
91
.string()
92
.describe("URL where you can view the generated PDF file"),
93
pdf: z
94
.string()
95
.describe(
96
`Information about reading the PDF from disk, e.g., an error if the PDF
97
does not exist.`,
98
),
99
}),
100
]);
101
102
export type LatexInput = z.infer<typeof LatexInputSchema>;
103
export type LatexOutput = z.infer<typeof LatexOutputSchema>;
104
105