# Markdown Preview

Markdown files normally open as rendered pages in *Lx*. You see the finished document instead of its Markdown marks.

Press *F9* or *Ctrl+Alt+E* when you want to edit the source. Press it again to return to the preview. Both views stay in the same tab and keep your place as closely as possible.

## What the preview shows

*Lx* handles the Markdown used in most everyday documents:

- Headings, paragraphs, and horizontal lines
- Bold, italic, combined bold italic, and inline code
- Numbered, bulleted, and nested lists
- Blockquotes
- Tables
- Fenced and indented code blocks
- Web links, local file links, and links to headings
- Full, collapsed, and shortcut reference-style links
- Standalone local images, including images used as links
- Inline and separate MaLxTeX formulas
- Markdown escapes and named or numbered character references

Markdown has many dialects. If *Lx* does not understand something, it keeps the source visible where possible.

## Code blocks

Use three or more backticks or tildes for a fenced code block. Add a language name after the opening fence to color the code:

````markdown
```lua
local answer = 42
```
````

The language name appears in a small badge. Known languages use their normal syntax colors. Unknown languages remain readable as plain code.

Lines indented by four spaces also appear as code blocks.

## MaLxTeX math

MaLxTeX is *Lx's* built-in TeX-compatible math renderer. It does not open a browser or load an outside math service.

Use single dollar signs for a formula inside a sentence:

```markdown
The area is $A = \pi r^2$.
```

Use dollar signs on separate lines for a larger formula:

```markdown
$$
\frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
$$
```

You can also use a fenced `math` block.

See [MaLxTeX](malxtex.md) for matrices, equation numbers, colors, macros, supported notation, and current limits.

## Document structure sidebar

The document structure sidebar shows the headings in your file. Indented headings belong under the heading above them.

The sidebar opens by default. Press *Ctrl+D* to hide or show it. Each preview remembers a manual choice while it remains open.

*Lx* highlights the section you are reading. Click a heading to jump to it. Press *Backspace* to return.

If the list is long, place the pointer over it and use the mouse wheel. You can also drag its scrollbar. The document itself stays in place.

The sidebar hides when the preview becomes too narrow. It returns when there is enough room.

You can move between headings without using the sidebar:

| Key | Action |
| --- | --- |
| *Alt+Up* or *Ctrl+PageUp* | Go to the previous heading |
| *Alt+Down* or *Ctrl+PageDown* | Go to the next heading |
| *Alt+Mouse Wheel* | Move through headings |

### Follow the window

You can make the sidebar appear only when the main window is maximized or fullscreen:

```lua
config.plugins.mdpreview.auto_document_outline = true
```

A manual *Ctrl+D* choice still wins for that preview.

## Move through the page

| Key | Action |
| --- | --- |
| *Up* or *Down* | Scroll by one rendered row |
| *Page Up* or *Page Down* | Scroll by one page |
| *Shift+Space* or *Space* | Scroll up or down by one page |
| *Home* or *Ctrl+Home* | Go to the top |
| *End* or *Ctrl+End* | Go to the bottom |
| *Backspace* | Return after jumping to a heading |

The mouse wheel scrolls normally. Drag with the left or middle mouse button to pan.

## Zoom

| Key | Action |
| --- | --- |
| *+* or *Ctrl+=* | Zoom in |
| *-* or *Ctrl+-* | Zoom out |
| *0* or *Ctrl+0* | Return to normal size |
| *Ctrl+Mouse Wheel* | Zoom around the pointer |

The keypad versions work too. The current zoom appears in the status bar.

## Open links

Click a link to open it:

- Web links open in your usual web browser.
- Links to local files open in *Lx*.
- Heading links move within the preview.

After following a heading link, press *Backspace* to return to the previous position.

Hover over a link to see its destination. Images with titles show their title after a short delay.

## Images

Standalone local images appear inside the preview. A relative path starts beside the Markdown file.

Remote images are not downloaded automatically. *Lx* shows a placeholder with the image address instead.

When a local image changes on disk, the preview refreshes its cached copy.

## Save the preview as images

Save the Markdown file, open the command palette, and run:

```text
preview:render-images
```

*Lx* saves the complete rendered document as numbered PNG pages beside the Markdown file. For `guide.md`, the names begin with `guide-001.png`, `guide-002.png`, and so on. Each page records `Original Filename` and its UTC `Creation Time` in PNG metadata.

The document structure sidebar is not included. Exporting again replaces the numbered pages. If the new version is shorter, old extra pages are removed.

These settings control the page size in pixels:

```lua
config.plugins.mdpreview.export_width = 2560
config.plugins.mdpreview.export_height = 3840
config.plugins.mdpreview.export_scale = "auto"
```

`"auto"` keeps the preview's current text size and wrapping in proportion to the wider export page. You can use a positive number such as `1.5` when you want a fixed export scale.

## Choose how Markdown opens

Use the command line when you want a different mode once:

```cli
lx --preview readme.md
lx --view readme.md
lx --edit readme.md
```

Use this setting to change the usual choice:

```lua
config.format_modes.md = "preview"
```

Use `"edit"` to open the Markdown source for editing. Use `"view"` for a read-only source view.

While reading, press *Alt+M* to move through the other available views. See [Opening Files](opening_files.md) for the complete opening order.

## Changes made by another program

A clean Markdown preview reloads when its file changes on disk. *Lx* keeps the same visible source area as closely as possible.

See [Files Changed Outside *Lx*](external_changes.md) for the full behavior.
