KScript docs
EN

latex fields and methods

A field is a plain fact about the value, read with a dot and no brackets: $value.name. A method takes arguments or does work, and is called with ->: $value->name(arguments), or with the value piped in: $value |> name(arguments).

Fields

FieldTypeDescription
.extensionstringThe source file extension without the dot.
.textstringThe source text of the fenced value.

From KScript.Document

These need <import package="KScript.Document" />import KScript.Document. See KScript.Document.

#latex->find(text: string) → number KScript.Document

The zero-based source offset of the first literal match, or -1.
ParameterTakes
text requiredstring
Example
<let name="paper" value="```latex
  \section*{Introduction}
  Some ideas.
  ```" />
<echo>{ $paper->find('ideas') }</echo>
$paper = ```latex
  \section*{Introduction}
  Some ideas.
  ```
echo $paper->find('ideas')

#latex->insert(content, at?: int) → latex KScript.Document

Returns a copy with text or source of the same format inserted at a zero-based offset. With no offset, appends.
ParameterTakes
content requiredany value
at optionalint

Arguments can be named: ->insert(…, at: …).

Example
<let name="paper" value="```latex
  \section*{Introduction}
  Some ideas.
  ```" />
<echo>{ $paper->insert(' More soon.').text }</echo>
$paper = ```latex
  \section*{Introduction}
  Some ideas.
  ```
echo $paper->insert(' More soon.').text

#latex->pages() → number KScript.Document

How many pages the PDF has.
Example
<let name="paper" value="```latex
  \section*{Introduction}
  Some \emph{ideas}.
  ```" />
<echo>{ $paper->pages() } pages</echo>
$paper = ```latex
  \section*{Introduction}
  Some \emph{ideas}.
  ```
echo "{ $paper->pages() } pages"

#latex->replace(search: string, replacement: string) → latex KScript.Document

Returns a copy with every literal match replaced.
ParameterTakes
search requiredstring
replacement requiredstring

Arguments can be named: ->replace(…, replacement: …).

Example
<let name="paper" value="```latex
  \section*{Introduction}
  Some ideas.
  ```" />
<echo>{ $paper->replace('ideas', 'plans').text }</echo>
$paper = ```latex
  \section*{Introduction}
  Some ideas.
  ```
echo $paper->replace('ideas', 'plans').text

#latex->save(path: string, as?: pdf|docx|'latex'|'markdown'|html) KScript.Document

Writes the document to a file. The filename extension (or as:) picks the format: .tex keeps the source, and .pdf, .docx, .md or .html renders the LaTeX a document part reads. With no extension, .tex.
ParameterTakes
path requiredstring
as optionalone of these words: pdf|docx|'latex'|'markdown'|html

Arguments can be named: ->save(…, as: …).

Example
<let name="paper" value="```latex
  \section*{Introduction}
  Some ideas.
  ```" />
<do>$paper->save('paper.tex')</do>
$paper = ```latex
  \section*{Introduction}
  Some ideas.
  ```
$paper->save('paper.tex')

#latex->words() → number KScript.Document

How many words the text has, not counting maths and code.
Example
<let name="paper" value="```latex
  \section*{Introduction}
  Some \emph{ideas}.
  ```" />
<echo>{ $paper->words() } words</echo>
$paper = ```latex
  \section*{Introduction}
  Some \emph{ideas}.
  ```
echo "{ $paper->words() } words"

Methods from any