• 【转】latexCommand


    来源:LaTeX:Commands

    This page introduces various useful commands for rendering math in LaTeX, as well as instructions for building your own commands.

    Contents

    Subscripts and Superscripts

    Make exponents in LaTeX with ^ and subscripts with _ as shown in the examples below.

    Symbol Command Symbol Command
    $2^{2}$ 2^2 $	extstyle a_i$ a_i
    $	extstyle 2^{23}$ 2^{23} $	extstyle n_{i-1}$ n_{i-1}
    $a^{i+1}_3$ a^{i+1}_3 $x{32}$ x{32}
    $2^{a_i}$ 2^{a_i} $2^a_i$ 2^a_i

    Notice that we can apply both a subscript and a superscript at the same time, and that we can use crimped brackets (${}$) to tell $	ext{LaTeX}$ what to apply a subscript or superscript to (compare the examples on the bottom row).

    Notice also that we put curly brackets around subscripts and superscripts with more than one character. You have to do so, or you'll end up with something such as $2^234$, when what you really want is $2^{234}$.

    Math Commands

    Here are some commonly used math commands in LaTeX.

    Fractions

    Symbol Command
    $frac 12$ frac 12
    $frac{2}{x+2}$ frac{2}{x+2}
    $frac{1+frac{1}{x}}{3x + 2}$ frac{1+frac{1}{x}}{3x + 2}

    Notice that with fractions with a 1-digit numerator and a 1-digit denominator, we can simply group the numerator and the denominator together as one number. However, for fractions with either a numerator or a denominator that requires more than one character, you need to surround everything in curly brackets.

    Use cfrac for continued fractions.

    Expression Command
    $cfrac{2}{1+cfrac{2}{1+cfrac{2}{1+cfrac{2}{1}}}}$ cfrac{2}{1+cfrac{2}{1+cfrac{2}{1+cfrac{2}{1}}}}

    Radicals

    Symbol Command
    $sqrt(latexCommand.assets/319cd9d243fa0f9de778cc9700ba4093587f4ed3.png)$ sqrt(2)
    $sqrt{2}$ sqrt{2}
    $sqrt{x+y}$ sqrt{x+y}
    $sqrt{x+frac{1}{2}}$ sqrt{x+frac{1}{2}}
    $sqrt[3]{3}$ sqrt[3]{3}
    $sqrt[n]{x}$ sqrt[n]{x}

    Sums, Products, Limits and Logarithms

    We use _ to get the 'bottom' parts of summations, products, and limits, as well as the subscripts of logarithms. We use ^ to get the 'top' parts of sums and products. (Integration symbols work the same way, as you'll see in the calculus section.) Click here for a few other commands which take 'bottom' parts.

    Symbol Command
    $	extstyle sum_{i=1}^{infty}frac{1}{i}$ sum_{i=1}^{infty}frac{1}{i}
    $	extstyle prod_{n=1}^5frac{n}{n-1}$ prod_{n=1}^5frac{n}{n-1}
    $	extstyle lim_{x	oinfty}frac{1}{x}$ lim_{x oinfty}frac{1}{x}
    $	extstyle log_n n^2$ log_n n^2

    Some of these are prettier in display mode:

    Symbol Command
    $sum_{i=1}^{infty}frac{1}{i}$ sum_{i=1}^{infty}frac{1}{i}
    $prod_{n=1}^5frac{n}{n-1}$ prod_{n=1}^5frac{n}{n-1}
    $lim_{x	oinfty}frac{1}{x}$ lim_{x oinfty}frac{1}{x}

    Note that we can use sums, products, and logarithms without _ or ^ modifiers.

    Symbol Command
    $sumfrac{1}{i}$ sumfrac{1}{i}
    $frac{n}{n-1}$ frac{n}{n-1}
    $	extstyle log n^2$ log n^2
    $	extstyle ln e$ ln e

    Mods

    Symbol Command
    $9equiv 3 mod{6}$ 9equiv 3 mod{6}
    $9equiv 3 pmod{6}$ 9equiv 3 pmod{6}
    $9equiv 3 mod{6}$ 9equiv 3 mod{6}
    $9equiv 3pod{6}$ 9equiv 3 pod{6}

    Combinations

    Symbol Command
    $scriptstyleinom{1}{1}$ inom{1}{1}
    $scriptstyleinom{n-1}{r-1}$ inom{n-1}{r-1}

    These often look better in display mode:

    Symbol Command
    $dbinom{9}{3}$ dbinom{9}{3}
    $dbinom{n-1}{r-1}$ dbinom{n-1}{r-1}

    Trigonometric Functions

    Most of these are just the abbreviation of the trigonometric function with simply a backslash added before the abbreviation.

    Symbol Command Symbol Command Symbol Command
    $	extstyle cos$ cos $	extstyle sin$ sin $	extstyle 	an$ an
    $sec$ sec $	extstyle 	extstyle csc$ csc $	extstyle cot$ cot
    $	extstyle arccos$ arccos $	extstyle arcsin$ arcsin $	extstyle arctan$ arctan
    $	extstyle cosh$ cosh $	extstyle sinh$ sinh $	extstyle 	anh$ anh
    $	extstyle coth$ coth

    Here are a couple examples:

    Symbol Command
    $	extstyle cos^2 x +sin^2 x = 1$ cos^2 x +sin^2 x = 1
    $cos 90^circ = 0$ cos 90^circ = 0

    Calculus

    Below are examples of calculus rendered in LaTeX. Most of these commands have been introduced before. Notice how definite integrals are rendered (and the difference between regular math and display mode for definite integrals). The , in the integrals makes a small space before the dx.

    Symbol Command
    $frac{d}{dx}left(latexCommand.assets/510acaeb98673d6e86620ff7d0399af8daee5f81.png) = 2x$ frac{d}{dx}left(x^2 ight) = 2x
    $int 2x,dx = x^2+C$ int 2x,dx = x^2+C
    $int^5_1 2x,dx = 24$ int^5_1 2x,dx = 24
    $int^5_1 2x,dx = 24$ int^5_1 2x,dx = 24
    $frac{partial^2U}{partial x^2} + frac{partial^2U}{partial y^2}$ frac{partial^2U}{partial x^2} + frac{partial^2U}{partial y^2}
    $frac{1}{4pi}oint_Sigmafrac{1}{r}frac{partial U}{partial n} ds$ frac{1}{4pi}oint_Sigmafrac{1}{r}frac{partial U}{partial n} ds

    Overline and Underline

    Symbol Command
    $overline{a+bi}$ overline{a+bi}
    $underline{747}$ underline{747}

    LaTeX

    Other Functions

    Symbol Command Symbol Command Symbol Command
    $arg$ arg $	extstyledeg$ deg $	extstyledet$ det
    $dim$ dim $	extstyleexp$ exp $	extstylegcd$ gcd
    $hom$ hom $inf$ inf $ker$ ker
    $	extstylelg$ lg $liminf$ liminf $limsup$ limsup
    $	extstylemax$ max $	extstylemin$ min $Pr$ Pr
    $sup$ sup

    Some of these functions take 'bottom' parts just like sums and limits. Some render differently in display mode and regular math mode.

    Symbol Command Symbol Command Symbol Command
    $dim_x$ dim_x $	extstylegcd_x$ gcd_x $inf_x$ inf_x
    $liminf_x$ liminf_x $limsup_x$ limsup_x $	extstylemax_x$ max_x
    $	extstylemin_x$ min_x $Pr_x$ Pr_x $sup_x$ sup_x

    Matrices

    We can build an array or matrix with the egin{array} command, and use left and ight to properly size the delimiters around the matrix:

    The characteristic polynomial $f(lambda)$ of the
    $3 	imes 3$ matrix
    [
    left(
    egin{array}{ccc}
    a & b & c <br />d & e & f <br />g & h & i end{array}
    
    ight)]
    is given by the equation
    [ f(lambda)
    = left|
    egin{array}{ccc}
    lambda - a & -b & -c <br />-d & lambda - e & -f <br />-g & -h & lambda - i end{array}
    
    ight|.]
    

    More simply, we can use the shortcut commands in the amsmath package:

    The characteristic polynomial $f(lambda)$ of the
    $3 	imes 3$ matrix
    [
    egin{pmatrix}
    a & b & c <br />d & e & f <br />g & h & i
    end{pmatrix} ]
    is given by the equation
    [ f(lambda)
    = egin{vmatrix}
    lambda - a & -b & -c <br />-d & lambda - e & -f <br />-g & -h & lambda - i
    end{vmatrix}.]
    

    You can read more about how the array command works here (it works the same as tabular).

    We can also use this environment to typeset any mathematics that calls for multiple columns, such as funky function definitions like this one:

    [ f(x) = left{ egin{array}{ll}
    x+7 & mbox{if $5< x$};<br />x^2-3 & mbox{if $-3 le x le 5$};<br />-x & mbox{if $x < -3$}.end{array} 
    ight. ]
    

    But it would be better to use the cases environment and ext command that the amsmath package provides:

    [ 
    f(x) = egin{cases}
    x+7 & 	ext{if $5< x$}; <br />x^2-3 & 	ext{if $-3 le x le 5$};<br />-x & 	ext{if $x < -3$}.
    end{cases}
    ]
    

    Text Styles in Math Mode

    You can render letters in various styles in math mode. Below are examples; you should be able to use these with any letters. The mathbb requires the amsfonts package to be included in your document's preamble. Do not try to do mathbb{year}. You'll get $mathbb{year}$, and that looks nothing like it!

    Symbol Command Symbol Command Symbol Command Symbol Command
    $mathbb{R}$ mathbb{R} $mathbf{R}$ mathbf{R} $mathcal{R}$ mathcal{R} $mathfrak{R}$ mathfrak{R}
    Mathbb1.gif mathbb{Z} $mathbf{Z}$ mathbf{Z} $mathcal{Z}$ mathcal{Z} $mathfrak{Z}$ mathfrak{Z}
    $mathbb{Q}$ mathbb{Q} $mathbf{Q}$ mathbf{Q} $mathcal{Q}$ mathcal{Q} $mathfrak{Q}$ mathfrak{Q}

    If you're persistent, you can dig a few more out of this document.

    If you want to drop a little bit of text in the middle of math mode, you can use the ext command. The ext command is most useful in $$...$$ or $...$ mode, where breaking up the math mode would force the output on to a new line entirely. So

    $$n^2 + 5 = 30	ext{ so we have }n=pm5$$
    

    gives

    Text1.gif

    How to Build Your Own Commands

    The command ewcommand is used to create your own commands. We'll start with an example:

    documentclass[11pt]{article}
    usepackage{amsmath}
    
    pdfpagewidth 8.5in
    pdfpageheight 11in
    
    ewcommand{
    eci}[1]{frac{1}{#1}}
    
    ewcommand{hypot}[2]{sqrt{#1^2+#2^2}}
    
    ewcommand{cbrt}[1]{sqrt[3]{#1}}
    
    egin{document}
    
    The reciprocal of 2 is $
    eci{2}$.
    
    The hypotenuse has length $hypot{3}{4}$.
    
    I'm sick of writing `$ackslash$sqrt[3]{2}$' all the time, just to get $cbrt{2}$.
    
    end{document}
    

    The ewcommand declarations are in the preamble. Each is of the form

    ewcommand{name of new command}[number of arguments]{definition}

    The name of the new command, which must begin with a , is the name you'll use in the document to use the command. The number of arguments is how many inputs will be sent to the command. The definition is just normal LaTeX code, with #1, #2, #3, etc., placed where you want the inputs to go when the new command is called.

    New commands can be used for all sorts of purposes, not just for making math commands you'll use a lot easier to call. For example, try this:

    documentclass[11pt]{article}
    usepackage{amsmath}
    
    pdfpagewidth 8.5in
    pdfpageheight 11in
    
    ewcounter{prob_num}
    setcounter{prob_num}{1}
    
    ewcommand{prob}[5]{igskip igskiparabic{prob_num}.stepcounter{prob_num} #1
    par
    opagebreak[4]medskip A. #2hfill B. #3hfill
    C. #4hfill D. #5hfill E. NOTA}
    
    egin{document}
    
    prob{What is $2+2$?}{4}{5}{6}{7}
    
    prob{What is $sqrt{100}$?}{81}{10}{9}{1}
    
    prob{Evaluate $sum_{n=1}^infty frac{1}{n^2}$.}
    {$frac{1}{e}$} {$frac{2}{pi}$}
    {$frac{pi^3}{8}$} {$frac{pi^2}{6}$}
    
    end{document}
    

    In the example above, we create a new command called prob. Each time we call prob, we supply 5 arguments, one for the question and one for each of the multiple choices.

    In the preamble and the definition of prob, you'll see a few new LaTeX commands:

    ewcounter{prob_num} creates a counter variable called prob_num

    setcounter{prob_num}{1} setsprob_num to equal 1.

    In the definition of prob, the igskip and medskip commands create vertical space.

    arabic{prob_num} prints out the current value of the counter prob_num as an arabic numeral.

    stepcounter{prob_num} increments the counter prob_num by 1.

    opagebreak[4] tells LaTeX not to break the page between the problem and the choices unless it really, really, really has to.

    The hfill commands put roughly equal space between the choices.

    Once you build a body of custom commands that you will be using in many LaTeX documents, you should learn about creating your own package so you don't have to copy all your custom commands from document to document.

    See Also

  • 相关阅读:
    mongodb数据库迁移
    idea激活
    常见加密方式
    restful请求风格使用详解
    Jreble破解使用
    websocket入门与分布式websocket
    分布式Session的解决方案
    mysql基础知识与优化总结
    分布式事务详解
    多线程总结与使用
  • 原文地址:https://www.cnblogs.com/dluff/p/12536366.html
Copyright © 2020-2023  润新知