# How to have multi-line pasted text show as multiple lines of text in mathjax.

The only way I know how to have multiline text "show" as multiline text is to add 4-5 leading spaces to each line of pasted text.

 line 1
line 2


This is tedious for many lines of text like code or data. Is there a mathjax command that makes each line use the carriage return within the pasted text without the leading spaces? Is there something like begin{} end{} that does what double backslashes do for math expressions but without having to add the backslashes?

• Re: This is tedious for many lines of text like code or data. In fact, you can do the same thing by selecting the text and pressing Ctrl+K.. Or by clicking the corresponding button in the editor. (Rather than adding four spaces manually for each line.) All these methods are mentioned also in the tag-info for code-block on Meta Stack Exchange. (Although it's quite possible that this is something completely different from what you're trying to achieve.) Feb 19, 2022 at 19:59
• @Martin Sleziak What I want to do in by browser window on Math Stack Exchange is be able to paste lines of text (perhaps between some pair of indicators) and have them show as separate lines of text. I want to do what I did here without having to add the leasing spaces. Feb 19, 2022 at 20:38
• If adding leading spaces to every line is equivalent to pressing a few keys once, why do you need something else? Feb 19, 2022 at 20:49
• @Misha Lavro I thought you were talking about a text editor or something. I tried the crtl-K thing and it added leading spaces to all the lines of text. It is a workable solution but it seems like there should be something that does not add spaces to the editing text. thanks. Feb 19, 2022 at 21:10
• Add two spaces to the end of each line of text to force a carriage return. Using code block formatting solely to force carriage returns is not recommended, since they interact differently with screen readers, for instance. (I’m not sure whether you’re asking to format code or plain text, hence this comment…) Feb 20, 2022 at 3:08
• and to finish @TheAmplitwist's comment; in case Mathjax is actually required, \begin{align}...\end{align}, \begin{array}...\end{array} and even $$...$$ (this last one is special to mathjax, does not work in LaTeX) supports multi-line output with two slashes \\. Text can be forced into Mathjax with \text{...} Feb 20, 2022 at 3:15
• @Calvin Khor I know to use several \begin{}, \end{}, \text{}, $$, and other formatting “commands”. I was hoping there was one to make the typesetter to respond to the carriage returns already in the text. Feb 20, 2022 at 3:28 • @poetasis At the risk of being too pedantic: there are three separate things working here. You can ask for linebreaks in normal text; you can do so in a codeblock; or you can force linebreaks in Mathjax. Mathjax is almost never used for the whole post. The Mathjax interpreter only starts working when it sees one of the ..., $$... or \begin{...}...\end{...} pairs. Without these things, Mathjax is not used, so it is not possible to ask Mathjax to do anything. In contrast, your example displays a code block, and does not use any Mathjax. Feb 20, 2022 at 5:20

As alluded to in the comments by Martin Sleziak, there are a few ways of creating code blocks:

## Inline code (for code that does not contain newlines)

• When the cursor is not in the first column, or you've selected code that does not hold newlines, click the {} code button above the editor (pictured below) or hit Ctrl+K (Cmd+K on macOS)
• Enclose with backticks: <html>
• Embed within <code> tags, and manually encode HTML entities: <code>&lt;html&gt;</code>

## Blocks of code (preserves newlines)

• When the cursor is on an empty line, or you've selected code including a newline, click the {} code button above the editor (pictured below) or hit Ctrl+K (Cmd+K on macOS)
• Create code fences with three backticks  or tildes ~~~, one on a line before the code, and one on a line after
• Indent the code by four spaces
• Encase in <pre> or <pre><code> tags (in that order; using <code><pre> is invalid), and encode HTML entities (like &lt; for <) yourself

All of these seem to work on my system.

Regarding the {}` icon:

I don't know that you can (or should) expect anything more. The goal here is to make it easy to input text with a fairly restricted number of (syntactic) formatting options. Code blocks are indicated by leading spaces. Those spaces can be inserted in a number of ways but, at the end of the day, they need to be there if you want a code block.

• Where is the '{}' icon? What formatting bar? Feb 20, 2022 at 0:21
• @poetasis here: i.stack.imgur.com/c2Hv7.png Feb 20, 2022 at 3:20
• @Calvin Khor What application has that formatting bar? I want something that works on math stack exchange in a browser window. I use Chrome. Feb 20, 2022 at 3:32
• @poetasis That is the top of the box used to write an Answer on this website. Here is a screenshot with more of the website shown. No added software. It is the same in all browsers. It is the same when writing a Question. (Sorry Xander for the pings) Feb 20, 2022 at 5:24
• @Calvin Khor I am surprised that I never saw that “bar” before because I have a habit of ignoring things that take up valuable vertical real estate. Thank you. Feb 20, 2022 at 9:23
• @poetasis glad to help! Feb 20, 2022 at 9:25