\newcommand - LaTeX命令



newcommand

\newcommand - 用於建立自定義命令(控制序列、宏、定義)。

概要

{ \newcommand\myCommandName
  [ <optional # of arguments, from 1 to 9> ]
  { <replacement text> } }

描述

\newcommand 命令用於定義自定義命令(控制序列、宏、定義);\newcommand 必須在使用前出現(在數學定界符內);如果需要,可以使用配置的 TeX.Macros 屬性在頭部定義宏。當沒有引數時,括號中的 # 引數將被省略。

示例

  1. \newcommand\myHearts 
     {\color{purple}{\heartsuit}\kern-2.5pt\color{green}{\heartsuit}}
    
    \myHearts\myHearts
    
    $ \newcommand\myHearts {\color{purple}{\heartsuit}\kern-2.5pt\color{green}{\heartsuit}} \myHearts\myHearts $
  2. \newcommand\myHearts[2] 
     {\color{#1}{\heartsuit}\kern-2.5pt\color{#2}{\heartsuit}}
      
    \myHearts{red}{blue}
    
    $ \newcommand\myHearts[2] {\color{#1}{\heartsuit}\kern-2.5pt\color{#2}{\heartsuit}} \myHearts{red}{blue} $
廣告
© . All rights reserved.