> 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-tw/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 程式碼主體

在所有情況下，都會依據以下設定自動建立「在 Overleaf 中開啟」連結： **`pre`**, **`主體`** 和 **`post`**

### 用於控制 Overleaf API 呼叫的參數（由 Alf 的作品繼承而來）

* **`engine`** 設定用於程式碼的編譯器，可為以下之一：
  * `pdflatex` （若未選擇 engine，則為預設值）
  * `xelatex`
  * `lualatex`
  * `latex_dvipdf`
* **`名稱`** 設定 Overleaf 文件的標題
* **`文字`** 設定用於顯示連結的文字

## 範例

以下章節列出此模板的一些範例用法。

### 定義 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-tw/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.
