Main Content

Format Text in the Live Editor

You can add formatted text, hyperlinks, images, and equations to your live scripts and functions to create a presentable document to share with others.

To insert a new item, go to theInserttab and select from the available options:

Option Description Additional Details

Code

Insert a blank line of code. You can insert a code line before, after, or between text lines.

Section Break

Insert a section break. You can insert a section break to divide your live script or function into manageable sections to evaluate individually. A section can consist of code, text, and output. For more information, seeCreate and Run Sections in Code.

Text

Insert a blank line of text. A text line can contain formatted text, hyperlinks, images, or equations. You can insert a text line before, after, or between code lines.

Table of Contents

Insert a table of contents.

The table of contents contains a list of all the titles and headings in the document. Only the title of the table of contents is editable.

You can insert a table of contents only in text lines. If you insert a table of contents into a code line, MATLAB®places it directly above the current code section.

When exporting a live script containing a table of contents toMicrosoft®Word, by default, the table of contents in the resulting document does not include page numbers. To add page numbers, click the table of contents and selectUpdate Table.

Code Example

Insert a formatted code example.

A code example is sample code that appears as indented and monospaced text.

  • SelectPlainto insert sample code as unhighlighted text.

  • SelectMATLABto insert sample code as text highlighted according to MATLAB syntax.

Image

Insert an image.

You can insert images only in text lines. If you insert an image into a code line, MATLAB places the image in a new text line directly under the selected code line.

To change the alternate text, alignment, and size of an image after inserting it, right-click the image and selectEdit Image...from the context menu.

  • Alt Text— Add text to the edit field to specify alternative text for the image.

  • Alignment— Select from the available options to specify how the image aligns with the other items in the row.

  • Size— To specify a size relative to the original image size, selectRelative (%)and specify the width and height of the image as a percentage of the original image. To specify an absolute size, selectAbsolute (px)and specify the width and height of the image in pixels. SelectKeep Aspect Ratioto maintain the aspect ratio while resizing.

    To return to the original image size, right-click the image and selectReset Image.

Hyperlink

Insert a hyperlink.

You can insert hyperlinks only in text lines. If you insert a hyperlink into a code line, MATLAB places the hyperlink in a new text line directly under the selected code line.

  • SelectWeb pageto insert a hyperlink to an external web page. Then, enter the URL of the web page.

  • SelectLocation in documentto insert a hyperlink that points to an existing location within the document. When prompted, click the desired location within the document to select it as the target. You also can use theAlt + Up ArrowandAlt + Down Arrowkeyboard shortcuts. Location can be a code section, text paragraph, title, or heading. Linking to individual lines of text or code is not supported.

  • SelectExisting fileto insert a hyperlink to a file. Then, enter the file path.

Equation

Insert an equation. You insert add equations only in text lines. If you insert an equation into a code line, MATLAB places the equation in a new text line directly under the selected code line. For more information, seeInsert Equations into the Live Editor.

To format existing text, use any of the options included in theLive EditortabTextsection:

Format Type Options
Text Style

Normal

Heading 1

Heading 2

Heading 3

Title

Text Alignment

Left

Center

Right

Lists

Numbered list

Bulleted list

Standard Formatting

Bold

Italic

Underline

Monospace

改变的情况下从一个选定的文本或代码ll uppercase to lowercase, or vice versa, select the text, right-click, and selectChange Case. You also can pressCtrl+Shift+A. If the text contains both uppercase and lowercase text, MATLAB changes the case to all uppercase.

Change Fonts

You can adjust the displayed font size in the Live Editor, or use settings to change the font name, style, size, and color of code and text.

To increase or decrease the displayed font size in the Live Editor, zoom in or out using theCtrl + Plus (+)andCtrl + Minus (-)keyboard shortcuts or by holdingCtrland scrolling with the mouse. OnmacOSsystems, use theCommandkey instead of theCtrl关键。The change in the displayed font size is not honored when exporting the live script to PDF,Microsoft Word, HTML, or LaTeX.

To change the font name, style, size, and color of code and text, using settings. For example, this code changes the color and style of titles in the Live Editor:

s = settings; s.matlab.fonts.editor.title.Style.PersonalValue = {'bold'}; s.matlab.fonts.editor.title.Color.PersonalValue = [0 0 255 1];

This code increases the size and changes the font name of normal text in the Live Editor:

s = settings; s.matlab.fonts.editor.normal.Size.PersonalValue = 20; s.matlab.fonts.editor.normal.Name.PersonalValue = 'Calibri';

The Live Editor updates all open live scripts and live functions to show the selected fonts. When you create new live scripts or functions, the selected fonts are applied as well.

live script with a title that is blue and bold, and a line of normal text in calibri size twenty font

For more information, seematlab.fonts Settings

Autoformatting

For quick formatting in live scripts and functions, you can use a combination of keyboard shortcuts and character sequences. Formatting appears after you enter the final character in a sequence.

This table shows a list of formatting styles and their available keyboard shortcuts and autoformatting sequences.

Formatting Style Autoformatting Sequence Keyboard Shortcut
Title

#text+Enter

Ctrl + Alt + L

Heading 1

##text+Enter

Ctrl + Shift + 1

Heading 2

###text+Enter

Ctrl + Shift + 2

Heading 3

####text+Enter

Ctrl + Shift + 3

Section break with heading 1

%%text+Enter

With cursor at beginning of line withtext:

Ctrl + Shift + 1, thenCtrl + Alt + Enter

Section break

%%+Enter

---+Enter

***+Enter

Ctrl + Alt + Enter

Bulleted list

*text

-text

+text

Ctrl + Alt + U

Numbered list

number.text

Ctrl + Alt + O

Italic

*text*

_text_

Ctrl + I

Bold

**text**

__text__

Ctrl + B

Bold and italic

***text***

___text___

Ctrl + B, thenCtrl + I

Monospace

`text`

|text|

Ctrl + M

Underline None

Ctrl + U

LaTeX equation

$LaTeX$

Ctrl + Shift + L

Hyperlink

URL+SpaceorEnter

<URL>

[Label](URL)

Ctrl + K

Trademark, service mark, and copyright symbols (™, ℠, ®, and ©)

(TM)

(SM)

(R)

(C)

None

Note

Title, heading, section break, and list sequences must be entered at the beginning of a line.

Sometimes you want an autoformatting sequence such as***to appear literally. To display the characters in the sequence, escape out of the autoformatting by pressing theBackspacekey or by clickingUndo. For example, if you type##text+Enter, a heading in the Heading 1 style with the wordtextappears. To undo the formatting style and simply display## text, press theBackspace关键。你只可以逃脱的直接序列y after completing it. After you enter another character or move the cursor, escaping is no longer possible.

回复乳胶方程的自动套用格式nd hyperlinks, use theBackspacekey at any point.

To force formatting to reappear after escaping out of a sequence, click theRedobutton. You only can redo an action directly after escaping it. After you enter another character or move the cursor, the redo action is no longer possible. In this case, to force the formatting to reappear, delete the last character in the sequence and type it again.

To disable all or certain autoformatting sequences, you can adjust theEditor/Debugger Autoformatting Preferences.

Related Topics