> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/zh-cn/shen-ru-wen-zhang/46-testing-display-and-link-template.md).

# 显示和链接模板测试

## 测试显示和链接模板

注意：持续测试中，因此结果可能会“波动”

## 用于显示 LaTeX 文档部分或全部内容的 MediaWiki 模板

提议的模板 [模板:OpenLaTeXInOverleaf](https://github.com/ayaka-notes/overleaf-learn-wiki/tree/main/learn/Template:OpenLaTeXInOverleaf/README.md) 可让你显示内联 LaTeX 代码 *和*，借鉴 Alf 的工作，自动生成一个 `在 Overleaf 中打开` 从内联 LaTeX 代码生成链接——你只需编写代码 *一次*。它还允许你只显示 `正文` 你的 LaTeX 内容，省略整个导言区和 \end{document}，或者显示整个文档，但无论哪种情况，都会在 Overleaf 中打开一个完整成型的文档。

* 注意：由于 MediaWiki 解析方面的原因， **你需要使用 `{{!}}` 在你的 TeX 代码中来生成 | 字符**.

### 用于控制 LaTeX 代码内联显示（以及文档构建）的参数

* **`pre`**，这会设置 `导言区` 你的文档。它默认为

```
\documentclass{article}
\begin{document}
```

* **`正文`** 这是你的 LaTeX 文档的核心代码
* **`post`**，这会设置

```
\end{document}
```

* **`show`** ，用于控制 LaTeX 代码的显示：可以是 `正文` 部分或整个文档
  * `show=ALL` 显示整个 LaTeX 文档——使用你的 `正文`, `pre` 和 `post`，或者使用 *默认值* 用于 `pre` 或 `post`.
  * `show=BODY` 只显示你的 LaTeX 代码的正文部分

在所有情况下，都会使用 **`pre`**, **`正文`** 和 **`post`**

### 用于控制 Overleaf API 调用的参数（通过 Alf 的工作继承而来）

* **`engine`** 设置用于代码的编译器，可为以下之一：
  * `pdflatex` （如果未选择引擎，则为默认值）
  * `xelatex`
  * `lualatex`
  * `latex_dvipdf`
* **`名称`** 设置 Overleaf 文档的标题
* **`text`** 设置用于显示链接的文本

## 示例

以下部分列出了一些该模板的示例用法。

### 定义 pre、post，并设置 show=ALL

```
{{OpenLaTeXInOverleaf|show=ALL|pre=
\documentclass{book}
\begin{document}
|body=

Hello

亲爱的

\LaTeX

|post=
\end{document}%这里我们结束文档
|engine=lualatex|name=使用 LuaLaTeX 的测试|text=在 Overleaf 中打开一个 LuaLaTeX 示例
}}
```

上述代码会生成以下内联显示和“在 Overleaf 中打开”链接

```latex
\documentclass{book}
\begin{document}
Hello

亲爱的

\LaTeX
\end{document}%这里我们结束文档
```

&#x20;[在 Overleaf 中打开一个 LuaLaTeX 示例](https://www.overleaf.com/docs?engine=lualatex\&snip_name=Test+using+LuaLaTeX\&snip=%5Cdocumentclass%7Bbook%7D%0A%5Cbegin%7Bdocument%7D%0AHello+%0A%0Adear%0A%0A%5CLaTeX%0A%5Cend%7Bdocument%7D%25Here+we+end+the+document)

### 定义 pre、post，并设置 show=BODY

```
{{OpenLaTeXInOverleaf|show=BODY|pre=
\documentclass{book}
\begin{document}
|body=

Hello

亲爱的

\LaTeX

|post=
\end{document}%这里我们结束文档
|engine=lualatex|name=使用 LuaLaTeX 的测试|text=在 Overleaf 中打开一个 LuaLaTeX 示例
}}
```

上述代码会生成以下内联显示和“在 Overleaf 中打开”链接

```latex
Hello

亲爱的

\LaTeX
```

&#x20;[在 Overleaf 中打开一个 LuaLaTeX 示例](https://www.overleaf.com/docs?engine=lualatex\&snip_name=Test+using+LuaLaTeX\&snip=%5Cdocumentclass%7Bbook%7D%0A%5Cbegin%7Bdocument%7D%0AHello+%0A%0Adear%0A%0A%5CLaTeX%0A%5Cend%7Bdocument%7D%25Here+we+end+the+document)

### 定义一个空的 pre、一个空的 post，但提供更完整的 body

```
{{OpenLaTeXInOverleaf|show=ALL|pre=|post=|body=

\documentclass{book}

\begin{document}

Hello

亲爱的

\LaTeX

\end{document}
|engine=lualatex|name=使用 LuaLaTeX 的测试|text=在 Overleaf 中打开一个 LuaLaTeX 示例
}}
```

上述代码会生成以下内联显示和“在 Overleaf 中打开”链接

```latex
\documentclass{book}

\begin{document}

Hello

亲爱的

\LaTeX

\end{document}
```

&#x20;[在 Overleaf 中打开一个 LuaLaTeX 示例](https://www.overleaf.com/docs?engine=lualatex\&snip_name=Test+using+LuaLaTeX\&snip=%5Cdocumentclass%7Bbook%7D%0A%0A%0A%5Cbegin%7Bdocument%7D%0A%0A%0AHello+%0A%0Adear%0A%0A%5CLaTeX%0A%0A%0A%5Cend%7Bdocument%7D)

### pre 和 post 使用默认值，但为 body 提供代码

```
{{OpenLaTeXInOverleaf|show=ALL|body=
Hello

亲爱的

\LaTeX
|engine=lualatex|name=使用 LuaLaTeX 的测试|text=在 Overleaf 中打开一个 LuaLaTeX 示例
}}
```

上述代码会生成以下内联显示和“在 Overleaf 中打开”链接

```latex
\documentclass{article}
\begin{document}

Hello

亲爱的

\LaTeX

\end{document}
```

&#x20;[在 Overleaf 中打开一个 LuaLaTeX 示例](https://www.overleaf.com/docs?engine=lualatex\&snip_name=Test+using+LuaLaTeX\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%0AHello+%0A%0Adear%0A%0A%5CLaTeX%0A%0A%5Cend%7Bdocument%7D)

## 测试，请忽略这些链接

```latex
\documentclass{article}
\begin{document}

\LaTeX

\end{document}
```

&#x20;[在 Overleaf 中打开](https://www.overleaf.com/docs?engine=\&snip_name=\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%0A%5CLaTeX%0A%0A%5Cend%7Bdocument%7D)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/zh-cn/shen-ru-wen-zhang/46-testing-display-and-link-template.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
