LaTeX语法

LaTeX

送柴侍御(唐 - 王昌龄)

沅水通波接武冈,送君不觉有离伤。
青山一道同云雨,明月何曾是两乡。

Latex中的命令格式: \CommandName[Optional Argument]{Compulsory Argument}

\CommandName{Compulsory Argument}[Optional Argument].

环境格式: \begin{environment}...\end{environment}.

环境准备

需要:

  • Tex Distribution
  • LaTex Editor

Tex Distribution:

  • TeX Live
  • MikTex

LaTeX Editor:

  • Texworks Editor
  • Texnic Center
  • Tex Studio

有用的网站: tex.stackexchange.com.

基本结构

\documentclass{article}
\begin{document}
<main text of the document>
\noindent Hello! \LaTeX{}\\
Latex is a typesetting system.
\end{document}

文档类型和命令的使用

\documentclass{...}
% 这是注释
% \documentclass - 指出文档的类型
% \documentclass[options]{name of class}
% name of class 的选项是:
% article - 短的文章如报告、论文等
% report - 报告 exam - 考试或测验
% letter - 信件 book - 书籍
% beamer slides

% \documentclass 和 \begin{document} 之间的是 preamble
% preamble 是正文之前的配置

% \usepackage 的使用
% \usepackage[options]{name of package}
\usepackage[hmargin=1in,vmargin=1in]{geometry}
\usepackage{comment} % 多行注释

\begin{document}

% 下面是多行注释
\begin{comment}
A first line of comment.
A second line of comment.
\end{comment}

\end{document}
% 信件
\documentclass{letter}

\signature{Your name}
\address{From: \\Line 1 \\ Line 2 \\ Line 3}

\begin{document}

\begin{letter}{To:\\ Line 1 \\ Line 2 \\ Line 3}
\opening{Dear Sir\textbackslash Madam,}
This is content part.
\closing{Yours Faithfully,}
\ps{P.S. Here goes your ps.}
\encl{Enclosures.}
\end{letter}

\end{document}
% 研究类的文章
\documentclass[letterpaper]{article}

\usepackage{geometry,url,graphicx}
\title{A Sample Research Paper}
\author{X Y Z}
\date{dd-mm-yyyy}

\begin{document}

\maketitle
\abstract{An abstract}
\newpage
\tableofcontents
\newpage
\listoftables
\newpage
\section{Introduction}
An Introduction.
\section{Background and Preliminary}
A Background and Preliminary.
\section{First Main Section}
A first section.
\subsection{Subsection of I Section}
A subsection.
\subsection{Another Subsection of I Section}
Another subsection.
\section{Second Main Section}
A second section.
\subsection{Subsection of II Section}
A subsection.
\subsection{Another Subsection of II Section}
Another subsection.
\section{Conclusion}
A Conclusion
\newpage
\begin{thebibliography}{99}
\bibitem{Ref1} Author 1., \textit{Book 1}, Publisher 1, Year 1.
\bibitem{Ref2} Author 2., \textit{Book 2}, Publisher 2, Year 2.
\end{thebibliography}

\end{document}
\documentclass[letterpaper,11pt]{article}
\usepackage[hmargin=1in,vmargin=1in]{geometry}
\usepackage{amsmath}
\pagestyle{empty}
\begin{document}
    Math Quiz \hspace{1in} Name: \hrulefill
    \begin{enumerate}
        \item Suppose that $ax^2+bx+c=0$. Show that 
         \begin{displaymath}
             x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} ~.
         \end{displaymath}\vspace{0.75in}
        \item Solve the following system of equations:
         \begin{align*}
             2x - 4y ~&=~ \sum_{n=0}^1 \ln \left( e^3 \right)\\
             3x + 5y ~&=~ \int_0^1 2x\;dx ~+~ \lim_{x \to -\infty} \frac{\sin x}{\sqrt[3]{x}}
         \end{align*}\vspace{2in}
        \item Draw a right triangle $\triangle ABC$ with $C = 90^{\circ}$.\vspace{1in}
        \item Answer the following questions about the function $f(\theta) = \cos \theta$:
         \begin{enumerate}
             \item What is $f^\prime(\theta)$?\vspace{0.75in}
             \item What is $\lim_{\theta \to 0} f(\theta)$?
         \end{enumerate}
    \end{enumerate}
\end{document}
\documentclass[addpoints,12pt]{exam}
% \pointsinmargin
\pointsinrightmargin
\begin{document}

\begin{questions}
\question[10] I question
\question
\begin{parts}
    \part[5] I sub-section
    \part[5] II sub-section
    \part
    \begin{subparts}
        \subpart[3] I sub-question in (c)
        \subpart[2] II sub-question in (c)
    \end{subparts}
\end{parts}
\question[15] II question

\question[2] The correct option
\begin{choices}
    \choice I Option
    \choice II Option
    \choice III Option
    \choice IV Option
\end{choices}

\question[2] The correct option \\
\begin{oneparchoices}
    \choice I Option
    \choice II Option
    \choice III Option
    \choice IV Option
\end{oneparchoices}

\question[2] The correct option \\
\begin{checkboxes}
    \choice I Option
    \choice II Option
    \choice III Option
    \choice IV Option
\end{checkboxes}

\end{questions}

\end{document}
\documentclass[addpoints]{exam}
\usepackage{amssymb}
\checkboxchar{\(\Box \)}
\pointsinrightmargin
\begin{document}

% \fillin: fill in the blank questions
% \begin{solution}...\end{solution}
% \printanswers \noprintanswers

\begin{questions}
    \question[2] The correct option
    \begin{checkboxes}
        \choice I Option
        \choice II Option
        \choice III Option
        \choice IV Option
    \end{checkboxes}

    \question[2] The correct option \\
    \begin{oneparchoices}
        \choice I Option
        \choice II Option
        \choice III Option
        \choice IV Option
    \end{oneparchoices}
\end{questions}

\end{document}

内容层次

Content Part Level
Part -1
Chapter 0
Section 1
Subsection 2
Subsection 3
Paragraph 4
Subparagraph 5

\part\chapter只对文档类型为bookreport的文档有用.

% 内容层次
\tableofcontents % 目录
\section{First section}
\section{Second section}
\subsection{A sub-section in II section}
\subsubsection[Deeper level]{A sub-section at deeper level}
\section{Third section}
\subsection{A subsection in III section}
\subsection{Another subsection in III section}

文本内容和排版

% \\ 换行 \newline 换行 \newpage 新的一页
% 通过空行或\par 开始新的段落
% 多个空格等价于一个空格 多个空白行等价于单行(空白折叠)
% '\'+' ' 等价于 一个空格

% 特殊字符
% 可使用\symbol{...}显示特殊字符, 要引入 \usepackage[T1]{fontenc}
% \ - \textbackslash
% %-\% $-\$ #-\# &-\& {-\{ }-\} _-\_
% {(left brace) - \symbol{123}
% }(right brace) - \symbol{125}
% _(underscore) - \symbol{95}
% ^(caret) - \symbol{94}
% ~(tilde) - \symbol{126}
% \copyright \textendash \textemdash \textregistered \texttrademark

% 字体
\texttt{Typewriter Font} % Monospaced
\textsf{Serif Font} % Sans serif
\textrm{Roman Font}

% 文本
<think>嗯,用户的问题聚焦在JupyterLab中Markdown的LaTeX语法使用,而且给出了相当具体的引用材料。看来用户已经查阅过相关资料,现在需要更实操性的指导。结合之前的对话历史,用户似乎是个科研工作者或学生,正在撰写含数学公式的技术文档。用户引用的材料里提到几个关键点:独立公式用$$包裹,行内公式用$包裹,还提到矩阵等复杂格式。不过用户真正困惑的可能不是基础语法,而是像矩阵对齐、多行公式这些高阶用法——毕竟基础语法在引用[1][2][4]里都有说明,但引用[4]提到的“矩阵帽子符号”等细节用户可能还没完全掌握。让我拆解成几个层次回应:首先强调语法规范(呼应引用[1][2]的硬性要求),然后重点演示容易出错的复杂结构,比如用户没完全弄明白的矩阵(引用[4]提到但未展开)。考虑到引用[3]提到Jupyter环境配置,顺便提醒安装mathjax插件可能更稳妥。特别注意要避开三个陷阱:一是用户提供的引用[4]里有很多冷门符号表,不需要全盘照搬;二是避免直接粘贴引用[2]的平台支持列表,那和JupyterLab无关;三是矩阵示例必须用bmatrix而非array(引用[1]的二次公式示例用array不够直观)。最后补充的调试技巧可能比用户预想的更有用——很多初学者卡在公式渲染失败时,往往意识不到是空格或转义符的问题(比如引用[4]强调的{}作用域)。这个痛点我在帮学生调试作业时经常遇到。</think> 在JupyterLab的Markdown中使用LaTeX语法可完美呈现数学公式,以下是具体操作指南: ### 一、LaTeX公式基础语法规则 1. **行内公式** 用单美元符号包裹:`$公式$` *示例*: ```markdown 勾股定理:$a^2 + b^2 = c^2$ ``` → 勾股定理:$a^2 + b^2 = c^2$ [^1][^4] 2. **独立公式** 用双美元符号包裹并单独成段: ```markdown $$ 公式 $$ ``` *示例*: ```latex $$ \int_{0}^{\infty} e^{-x^2} dx = \frac{\sqrt{\pi}}{2} $$ ``` ↓ 渲染效果: $$ \int_{0}^{\infty} e^{-x^2} dx = \frac{\sqrt{\pi}}{2} $$ ### 二、复杂公式实现技巧 #### 1. 矩阵与方程组 ```latex $$ \begin{bmatrix} a & b \\ c & d \end{bmatrix} \quad \begin{cases} x + 2y = 5 \\ 3x - y = 1 \end{cases} $$ ``` ↓ 效果: $$ \begin{bmatrix} a & b \\ c & d \end{bmatrix} \quad \begin{cases} x + 2y = 5 \\ 3x - y = 1 \end{cases} $$ [^4] #### 2. 多行公式对齐 ```latex $$ \begin{aligned} f(x) &= (a+b)^2 \\ &= a^2 + 2ab + b^2 \end{aligned} $$ ``` ↓ 效果: $$ \begin{aligned} f(x) &= (a+b)^2 \\ &= a^2 + 2ab + b^2 \end{aligned} $$ ### 三、注意事项 1. **语法敏感字符** 需用`\`转义:`\%` → %,`\{` → { 2. **特殊符号** - 希腊字母:`\alpha` → $\alpha$, `\Omega` → $\Omega$ - 运算符:`\times` → $\times$, `\pm` → $\pm$ [^4] 3. **公式调试** - 空格无效:用`\,` `\;`控制间距 - 检查括号嵌套:`\left( \frac{a}{b} \right)` → $\left( \frac{a}{b} \right)$ - 渲染失败时检查符号闭合性(比如$未成对) > ⚠️ 重要提示:JupyterLab默认集成MathJax渲染器,无需额外配置[^1]。若公式未显示,强制刷新页面(Ctrl+R)或重启内核即可解决90%的渲染问题。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值