Stata 15 help for text

[G-4] text -- Text in graphs

Description

Text elements in Stata graphs, like text in the rest of Stata, can contain Unicode characters. In addition, all text elements in Stata graphs support the use of certain SMCL markup directives, or tags, to affect how they appear on the screen. SMCL, which stands for Stata Markup and Control Language and is pronounced "smickle", is Stata's output language and is discussed in detail in [P] smcl.

All text output in Stata, including text in graphs, can be modified with SMCL.

For example, you can italicize a word in a graph title:

. scatter mpg weight, title("This is {it:italics} in a graph title") (click to run)

This entry documents the features of SMCL that are unique to graphs. We recommend that you have a basic understanding of SMCL before reading this entry; see [P] smcl.

Remarks

Remarks are presented under the following headings:

Overview Bold and italics Superscripts and subscripts Fonts, standard Fonts, advanced Greek letters and other symbols Full list of SMCL tags useful in graph text

Overview

Assuming you read [P] smcl before reading this entry, you know about the four syntaxes that SMCL tags follow. As a refresher, the syntaxes are

Syntax 1: {xyz} Syntax 2: {xyz:text} Syntax 3: {xyz args} Syntax 4: {xyz args:text}

Syntax 1 means "do whatever it is that {xyz} does". Syntax 2 means "do whatever it is that {xyz} does, do it on the text text, and then stop doing it". Syntax 3 means "do whatever it is that {xyz} does, as modified by args". Finally, syntax 4 means "do whatever it is that {xyz} does, as modified by args, do it on the text text, and then stop doing it".

Most SMCL tags useful in graph text follow syntax 1 and syntax 2, and one ({fontface}) follows syntax 3 and syntax 4.

Bold and italics

Changing text in graphs to bold or italics is done in exactly the same way as in the Results window. Simply use the SMCL {bf} and {it} tags:

. scatter mpg weight, caption("{bf:Source}: {it:Consumer Reports}, used with permission")} (click to run)

{bf} and {it} follow syntaxes 1 and 2.

Superscripts and subscripts

You can include superscripts and subscripts in text in graphs. This may surprise you, because it is not possible to do so with text in the Results window. Because graphs are not constrained to use fixed-width fonts and fixed-height lines like output in the Results window, it is possible to allow more features for text in graphs.

It is simple to use the {superscript} and {subscript} tags to cause a piece of text to be displayed as a superscript or a subscript. Here we will plot a function and will change the title of the graph to something appropriate:

. twoway function y = 2*exp(-2*x), range(0 2) /// title("{&function}(x)=2e{superscript:-2x}") (click to run)

{superscript} and {subscript} follow syntaxes 1 and 2. {sup} and {sub} may be used as shorthand for {superscript} and {subscript}.

The example above also demonstrates the use of a symbol, {&function}; symbols will be discussed in more detail below.

Fonts, standard

Stata provides four standard font faces for graphs to allow text to be displayed in a sans-serif font (the default), a serif font, a monospace (fixed-width) font, or a symbol font. These fonts have been chosen to work across operating systems and in graphs exported to PostScript and Encapsulated PostScript files. Unicode characters, such as Chinese characters, which are not available in the Latin1 encoding, are not available in PostScript, because PostScript fonts do not support them.

The SMCL tags used to mark text to be displayed in any of these fonts and the fonts that are used on each type of system are shown below:

SMCL | {stSans} {stSerif} {stMono} {stSymbol} --------+-------------------------------------------------------- Windows | Arial Times New Roman Courier New Symbol Mac | Helvetica Times Courier Symbol Unix | Sans Serif Monospace Sans PS/EPS | Helvetica Times Courier Symbol

Note: We recommend that you leave in place the mapping from these four SMCL tags to the fonts we have selected for each operating system. However, you may override the default fonts if you wish. See [G-2] graph set for details.

Changing fonts within text on a graph is easy:

. scatter mpg weight, title("Here are {stSerif:serif}, {stSans:sans serif}, and {stMono:monospace}") (click to run)

{stSans}, {stSerif}, {stMono}, and {stSymbol} follow syntaxes 1 and 2.

The {stSymbol} tag lets you display hundreds of different symbols, such as Greek letters and math symbols. There are so many possibilities that symbols have their own shorthand notation to help you type them and have their own section describing how to use them. See Greek letters and other symbols below. Remember that you can also use Unicode characters.

Fonts, advanced

In addition to the four standard fonts, you may display text in a graph using any font available on your operating system by using the {fontface} tag. If the font face you wish to specify contains spaces in its name, be sure to enclose it in double quotes within the {fontface} tag. For example, to display text using a font on your system named "Century Schoolbook", you would type

. scatter mpg weight, title(`"Text in {fontface "Century Schoolbook":a different font}"') (click to run)

If the font face you specify does not exist on your system, the operating system will substitute another font.

{fontface} follows syntaxes 3 and 4.

The four standard fonts may also be specified using the {fontface} tag. For example, you can specify the default serif font with {fontface "stSerif"}; in fact, {stSerif} is shorthand for exactly that.

If you choose to change fonts in graphs by using the {fontface} tag, keep in mind that if you share your Stata .gph files with other Stata users, they must have the exact same fonts on their system for the graphs to display properly. Also, if you need to export your graphs to PostScript or Encapsulated PostScript files, Stata will have to try to convert your operating system's fonts to PostScript fonts and embed them in the exported file. It is not always possible to properly convert and embed all fonts, which is why we recommend using one of the four standard fonts provided by Stata.

In Stata for Unix, if you use fonts other than the four standard fonts and you wish to export your graphs to PostScript or Encapsulated PostScript files, you may need to specify the directory where your system fonts are located; see [G-3] ps_options.

Greek letters and other symbols

Stata provides support for many symbols in text in graphs, including both capital and lowercase forms of the Greek alphabet and many math symbols.

You may already be familiar with the {char} tag -- synonym {c} -- which follows syntax 3 and allows you to output any ASCII character. If not, see Displaying characters using ASCII code in [P] smcl. All the features of {char}, except for the line-drawing characters, may be used in graph text.

Graph text supports even more symbols than {char}. For the symbols Stata supports, we have chosen to define SMCL tags with names that parallel HTML character entity references. HTML character entity references have wide usage and, for the most part, have very intuitive names for whatever symbol you wish to display.

In HTML, character entity references are of the form "&name;", where name is supposed to be an intuitive name for the given character entity. In SMCL, the tag for a given character entity is "{&name}".

For example, in HTML, the character reference for a capital Greek Sigma is Σ. In SMCL, the tag for a capital Greek Sigma is {&Sigma}.

In some cases, the HTML character reference for a particular symbol has a name that is not so intuitive. For example, HTML uses ƒ for the "function" symbol (f). SMCL provides {&fnof} to match the HTML character reference, as well as the more intuitive {&function}.

All SMCL symbol tags follow syntax 1.

See Full list of SMCL tags useful in graph text for a complete list of symbols supported by SMCL in graphs.

As an example, we will graph a function and give it an appropriate title:

. twoway function y = gammaden(1.5,2,0,x), range(0 10) /// title("{&chi}{sup:2}(3) distribution") (click to run)

Graphs rendered to the screen or exported to disk will typically display Greek letters and other math symbols with Unicode characters using the current font. The Postscript format does not support Unicode characters, so Greek letters and other math symbols are displayed using the {stSymbol} font. For example, {&Alpha} is equivalent to {stSymbol:A}.

Full list of SMCL tags useful in graph text

The SMCL tags that are useful in graph text are the following:

SMCL tag Description -------------------------------------------------------------------- {bf} Make text bold {it} Make text italic {superscript} Display text as a superscript {sup} Synonym for {superscript} {subscript} Display text as a subscript {sub} Synonym for {subscript} {stSans} Display text with the default sans serif font {stSerif} Display text with the default serif font {stMono} Display text with the default monospace (fixed-width) font {stSymbol} Display text with the default symbol font {fontface "fontname"} Display text with the specified fontname {char code} Display ASCII character {&symbolname} Display a Greek letter, math symbol, or other symbol --------------------------------------------------------------------

The Greek letters supported by SMCL in graph text are the following:

SMCL tag Description -------------------------------------------------------------------- {&Alpha} Capital Greek letter Alpha {&Beta} Capital Greek letter Beta {&Gamma} Capital Greek letter Gamma {&Delta} Capital Greek letter Delta {&Epsilon} Capital Greek letter Epsilon {&Zeta} Capital Greek letter Zeta {&Eta} Capital Greek letter Eta {&Theta} Capital Greek letter Theta {&Iota} Capital Greek letter Iota {&Kappa} Capital Greek letter Kappa {&Lambda} Capital Greek letter Lambda {&Mu} Capital Greek letter Mu {&Nu} Capital Greek letter Nu {&Xi} Capital Greek letter Xi {&Omicron} Capital Greek letter Omicron {&Pi} Capital Greek letter Pi {&Rho} Capital Greek letter Rho {&Sigma} Capital Greek letter Sigma {&Tau} Capital Greek letter Tau {&Upsilon} Capital Greek letter Upsilon {&Phi} Capital Greek letter Phi {&Chi} Capital Greek letter Chi {&Psi} Capital Greek letter Psi {&Omega} Capital Greek letter Omega {&alpha} Lowercase Greek letter alpha {&beta} Lowercase Greek letter beta {&gamma} Lowercase Greek letter gamma {&delta} Lowercase Greek letter delta {&epsilon} Lowercase Greek letter epsilon {&zeta} Lowercase Greek letter zeta {&eta} Lowercase Greek letter eta {&theta} Lowercase Greek letter theta {&thetasym} Greek theta symbol {&iota} Lowercase Greek letter iota {&kappa} Lowercase Greek letter kappa {&lambda} Lowercase Greek letter lambda {&mu} Lowercase Greek letter mu {&nu} Lowercase Greek letter nu {&xi} Lowercase Greek letter xi {&omicron} Lowercase Greek letter omicron {&pi} Lowercase Greek letter pi {&piv} Greek pi symbol {&rho} Lowercase Greek letter rho {&sigma} Lowercase Greek letter sigma {&sigmaf} Greek 'final' sigma symbol {&tau} Lowercase Greek letter tau {&upsilon} Lowercase Greek letter upsilon {&upsih} Greek upsilon with a hook symbol {&phi} Lowercase Greek letter phi {&chi} Lowercase Greek letter chi {&psi} Lowercase Greek letter psi {&omega} Lowercase Greek letter omega --------------------------------------------------------------------

Math symbols supported by SMCL in graph text are the following:

SMCL tag Description -------------------------------------------------------------------- {&weierp} Weierstrass p, power set {&image} Imaginary part {&imaginary} Synonym for {&image} {&real} Real part {&alefsym} Alef, first transfinite cardinal {&amp} Ampersand {&lt} Less than {&gt} Greater than {&le} Less than or equal to {&ge} Greater than or equal to {&ne} Not equal to {&fnof} Function {&function} Synonym for {&fnof} {&forall} For all {&part} Partial differential {&exist} There exists {&empty} Empty set, null set, diameter {&nabla} Nabla, backward difference {&isin} Element of {&element} Synonym for {&isin} {&notin} Not an element of {&prod} N-ary product, product sign {&sum} N-ary summation {&minus} Minus sign {&plusmn} Plus-or-minus sign {&plusminus} Synonym for {&plusmn} {&lowast} Asterisk operator {&radic} Radical sign, square root {&sqrt} Synonym for {&radic} {&prop} Proportional to {&infin} Infinity {&infinity} Synonym for {&infin} {&ang} Angle {&angle} Synonym for {&ang} {&and} Logical and, wedge {&or} Logical or, vee {&cap} Intersection, cap {&intersect} Synonym for {&cap} {&cup} Union, cup {&union} Synonym for {&cup} {&int} Integral {&integral} Synonym for {&int} {&there4} Therefore {&therefore} Synonym for {&there4} {&sim} Tilde operator, similar to {&cong} Approximately equal to {&asymp} Almost equal to, asymptotic to {&equiv} Identical to {&sub} Subset of {&subset} Synonym for {&sub} {&sup} Superset of {&superset} Synonym for {&sup} {&nsub} Not a subset of {&nsubset} Synonym for {&nsub} {&sube} Subset of or equal to {&subsete} Synonym for {&sube} {&supe} Superset of or equal to {&supersete} Synonym for {&supe} {&oplus} Circled plus, direct sum {&otimes} Circled times, vector product {&perp} Perpendicular, orthogonal to, uptack {&orthog} Synonym for {&perp} {&sdot} Dot operator {&dot} Synonym for {&sdot} {&prime} Prime, minutes, feet {&Prime} Double prime, seconds, inches {&frasl} Fraction slash {&larr} Leftward arrow {&uarr} Upward arrow {&rarr} Rightward arrow {&darr} Downward arrow {&harr} Left-right arrow {&crarr} Downward arrow with corner leftward, carriage return {&lArr} Leftward double arrow, is implied by {&uArr} Upward double arrow {&rArr} Rightward double arrow, implies {&dArr} Downward double arrow {&hArr} Left-right double arrow --------------------------------------------------------------------

Other symbols supported by SMCL in graph text are the following:

SMCL tag Description -------------------------------------------------------------------- {&trade} Trademark {&trademark} Synonym for {&trade} {&reg} Registered trademark {&copy} Copyright {&copyright} Synonym for {&copy} {&bull} Bullet {&bullet} Synonym for {&bull} {&hellip} Horizontal ellipsis {&ellipsis} Synonym for {&hellip} {&loz} Lozenge, diamond {&lozenge} Synonym for {&loz} {&diamond} Synonym for {&loz} {&spades} Spades card suit {&clubs} Clubs card suit {&hearts} Hearts card suit {&diams} Diamonds card suit {&diamonds} Synonym for {&diams} {&degree} Degrees --------------------------------------------------------------------


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index