KScript 文档
ZH

latex 字段和方法

字段是关于值的一个普通事实,用点号读取,不需要方括号:$value.name。方法会接收参数或执行操作,调用方式为 ->:$value->name(arguments),也可以把值通过管道传入:$value |> name(arguments)。

字段

字段类型说明
.extensionstring源文件扩展名(不含点)。
.textstring带围栏值的源文本。

来自 KScript.Document

这些需要 <import package="KScript.Document" />import KScript.Document。参见 KScript.Document。

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

首个字面匹配的从零开始的源偏移量,若无匹配则为 -1。
参数接受
text 必需string
示例
<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

返回一个副本,在从零开始的偏移位置插入相同格式的文本或源码。未指定偏移时则追加到末尾。
参数接受
content 必填任意值
at 可选int

参数可以使用命名方式:->insert(…, at: …)。

示例
<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() → 数字 KScript.Document

PDF 文件的页数。
示例
<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

返回一个副本,其中每个字面匹配项都被替换。
参数接受
search 必填string
replacement 必填string

参数可以使用命名方式:->replace(…, replacement: …)。

示例
<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

将文档写入文件。文件扩展名(或 as:)决定格式:.tex 保留源代码,.pdf、.docx、.md 或 .html 则渲染文档部分所读取的 LaTeX。若未指定扩展名,则默认为 .tex。
参数接受
path 必需string
as 可选以下词之一:pdf|docx|'latex'|'markdown'|html

参数可以使用命名方式:->save(…, as: …)。

示例
<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() → 数字 KScript.Document

文本的字数(不计数学公式和代码)。
示例
<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"

来自 any 的方法