# \rule

Used to insert a solid rectangular rule with a specified width and height, optionally shifted vertically via an optional bracket argument.

https://texform.dev/latex/commands/rule

## Metadata

| Field | Value |
| --- | --- |
| Topic | [Layout and breaks](https://texform.dev/latex/topics/layout) |
| Packages | base, textmacros |
| Allowed mode | math, text |
| Tags |  |
| Commonality | medium |
| Kind | prefix |

## Syntax

### base

Argument specification: `o:L m:L m:L`

Used to insert a solid rectangular rule with a specified width and height, optionally shifted vertically via an optional bracket argument.

### textmacros

Argument specification: `o:L m:L m:L`

Used in text mode to draw a solid rule of specified width and thickness, optionally raised or lowered by an offset.

## Examples

```latex
\rule{2em}{3em}
```

[Open in Playground](https://play.texform.dev/?input=%5Crule%7B2em%7D%7B3em%7D)

```latex
\rule[1em]2em3em
```

[Open in Playground](https://play.texform.dev/?input=%5Crule%5B1em%5D2em3em)

```latex
\text{\rule{1em}{2pt}}
```

[Open in Playground](https://play.texform.dev/?input=%5Ctext%7B%5Crule%7B1em%7D%7B2pt%7D%7D)

```latex
\text{\rule[3pt]1em 2pt}
```

[Open in Playground](https://play.texform.dev/?input=%5Ctext%7B%5Crule%5B3pt%5D1em+2pt%7D)

## Package variants

| Package | Argument specification | Allowed mode | Description |
| --- | --- | --- | --- |
| base | o:L m:L m:L | math | Used to insert a solid rectangular rule with a specified width and height, optionally shifted vertically via an optional bracket argument. |
| textmacros | o:L m:L m:L | text | Used in text mode to draw a solid rule of specified width and thickness, optionally raised or lowered by an offset. |

## Renderer support

| Package | MathJax | KaTeX | XeTeX |
| --- | --- | --- | --- |
| base | full | partial | partial |
| textmacros | full | partial | partial |

## In TeXForm

TeXForm parses this entry as prefix syntax; the package determines its argument specification.

## Test cases

### base

| Input | Case | MathJax | KaTeX | XeTeX |
| --- | --- | --- | --- | --- |
| \rule{1pt}{1pt} | Positive: baseline | Pass | Pass | Pass |
| \rule[1pt]{1pt}{1pt} | Positive: vary:o[0] | Pass | Pass | Pass |
| \rule 1pt{1pt} | Positive: bare[1] | Pass | Fail | Fail |
| \rule{1pt}1pt | Positive: bare[2] | Pass | Pass | Fail |
| \rule[a]{1pt}{1pt} | Negative: neg:L[0] | Pass | Fail | Fail |
| \rule{a}{1pt} | Negative: neg:L[1] | Fail | Fail | Fail |
| \rule{1pt}{a} | Negative: neg:L[2] | Fail | Fail | Fail |

### textmacros

| Input | Case | MathJax | KaTeX | XeTeX |
| --- | --- | --- | --- | --- |
| \rule{1pt}{1pt} | Positive: baseline | Pass | Pass | Pass |
| \rule[1pt]{1pt}{1pt} | Positive: vary:o[0] | Pass | Pass | Pass |
| \rule 1pt{1pt} | Positive: bare[1] | Pass | Fail | Fail |
| \rule{1pt}1pt | Positive: bare[2] | Pass | Pass | Fail |
| \rule[a]{1pt}{1pt} | Negative: neg:L[0] | Pass | Fail | Fail |
| \rule{a}{1pt} | Negative: neg:L[1] | Fail | Fail | Fail |
| \rule{1pt}{a} | Negative: neg:L[2] | Fail | Fail | Fail |
