Template:Math

维基百科,自由的百科全书
跳转至: 导航搜索

{{{1}}}

Documentation icon 模板文档[查看] [编辑] [页面历史] [清除]

The math template formats HTML- or wikimarkup generated mathematical formulas in the similar fashion as MathJax, a web-based TeX formula interpreter. The template uses the texhtml class, which aims to match the size of the serif font with the surrounding sans-serif font (see below). The template also prevents line-wrapping.

Use this template for non-complex formulas as an alternative to using the <math>……</math> format (see: Help:Math).

Usage[编辑]

Use this template to wrap an inline formula in wikitext.

Examples[编辑]

{{math|''f''(''x'') {{=}} ''b''<sup>''x''</sup> {{=}} ''y''}}
produces: f(x) = bx = y
{{math|sin &pi; {{=}} 0}}
produces: sin π = 0.
{{math|{{intmath|int|0|+&infin;}} ''e''<sup>{{minus}}''x''</sup> d''x'' {{=}} 1}}
produces: +∞
0
ex dx = 1
'''{{math|{{sfrac|1|2}} {{minus}} {{sfrac|1|3}} {{=}} {{sfrac|1|6}}}}'''
produces: 1/21/3 = 1/6. Note the triple-apostrophes have set the whole formula as bold.
{{math|({{sqrt|2}})<sup>2</sup> {{=}} 2}}
produces: (2)2 = 2.

Use of equals-sign and absolute value bars[编辑]

If a single equals-sign ("=") is used, it will fail to render, instead showing "{{{1}}}". For example, the following template-coding would be invalid:

{{math|1 + 2 = 3}}
produces: {{{1}}}, which is invalid code

To resolve this, either: (a) Start the formula with "1=" as in:

{{math|1=1 + 2 = 3}}
produces: 1 + 2 = 3, or else, (b) include the equals-sign in double-braces "{{=}}" as in:
{{math|1 + 2 {{=}} 3}}
produces: 1 + 2 = 3.

A similar difficulty concerns the vertical bars ("|") used to indicate absolute value, which without care would get interpreted as part of the template syntax. The solution is different than for the equals sign: such bars should be entered as "{{!}}":

{{math|{{!}}''f''(''x'') − ''a''{{!}} < ε}}
produces: |f(x) − a| < ε.

This example can also be produced by the following:

{{math|{{mabs|''f''(''x'') − ''a''}} < ε}}
produces: |f(x) − a| < ε

Parameters[编辑]

The following parameters are optional:

  • big=1 – This will render the formula in a bigger fontsize, increased to 165%.
  • size=font-size – Use this to specify your own fontsize.
{{math|big=1|1 + 2 {{=}} 3}}
produces: 1 + 2 = 3

TemplateData[编辑]

这是一个用于新版可视化编辑器模板数据文档。

Math

This template formats markup generated mathematical formulas with HTML and CSS. The template tries to match the size of the serif font with the surrounding sans-serif font. The template also prevents line-wrapping. Use this template for non-complex formulas as an alternative to using the <math> format.

模板参数
参数 说明 类型 默认值 状态
formula 1 wrap an inline formula in wikitext. string 必填
bigger font size big if set to ‘1’, this will render the formula in a bigger font size, increased to 165% string 可选
custom font size size use this to specify your own font size string 可选

Notes[编辑]

The font and fontsize used for texhtml, as defined in MediaWiki:Common.css, was determined by comparing common default fonts found on Windows, OS X and Linux and is scaled to 118% to match their x-height. However, not everyone uses the default fonts. If you find that the rendered math is not of the same size as the surrounding text, you can adjust this in your personal CSS. For instance, the DejaVu Sans and DejaVu Serif fonts do not need scaling, in which case span.texhtml { font-size: 100%; } will restore proper display.

The texhtml classname is a remnant from the TeX renderer, which had a user preference to render TeX-written formulae in "HTML when simple". That option has been removed some time ago, but the classname continues to be used for formulae written in HTML.

See also[编辑]

Help and information
Related templates