Tag Info

Hot answers tagged

40

Answering my own question after much research, experimentation, and testing. stevem's pointer to to the Mac OS X TeX Toolbox approach (store the TeX snippet in a box and write the height, width, and depth to a file) was the crucial key to the puzzle. I followed that approach, made some adjustments and additions, and came up with a solution that is not only ...


30

Update: Example added without amstext to show the effect of this package on the other \text... commands. Example file without package amstext (or amsmath): \documentclass{article} \usepackage[T1]{fontenc} \usepackage{lmodern} \usepackage{tgpagella} \newcommand*{\test}[1]{% $\csname #1\endcsname{#1}^{\csname #1\endcsname{#1}}$% } ...


27

The real reason for not allowing \theta in normal text has to do with how TeX deals with fonts. A TeX font has only 256 slots, while the mathematical symbols are many more. The command \theta is, essentially, a four digit hexadecimal number: 0x0112 which carries a good deal of information: the leftmost digit is 0 and tells TeX that it's an ordinary ...


22

Although it's a bit overkill, you could use the \num macro of the siunitx package: \documentclass{article} \usepackage{siunitx} \begin{document} \Huge In mathmode: \(-9\) With \textsf{siunitx}: \num{-9} \end{document}


21

A package? The following simple macro does it: \documentclass{article} \newcount\smcount \def\smart#1{\ifcase\smcount(\or[\or\{\else TOO DEEP!\fi% \advance\smcount by1 #1\ifcase\smcount\or)\or]\or\}\else TOO DEEP!\fi% \advance\smcount by-1 } \begin{document} \smart{Ala \smart{ma \smart {kota}}} \end{document} (Or, if you wish, not \smart but ...


19

For comparison I am posting a ConTeXt solution. Such a macro already exists, albeit for quotes. One of the good things about ConTeXt is that a feature is never defined in a one-off basis. For example, instead of defining a macro for quotations that changes the quote symbol depending on the level of nesting, ConTeXt defines a generic delimitedtext mechanism ...


19

I think amsmath's \text is just OK. Quoted from document of amstext: The \text macro is a sophisticated command which allows the user to insert “normal text” into math formulas without worrying about correct sizes in sub- or superscripts. It can also be used in ordinary text; there it produces an unbreakable unit similar to \mbox.


16

Here is an approach which is somewhat more modular than alexurba's approach, which accomodates indefinite levels of nesting. \makeatletter \def\@enparen#1{\bgroup\let\enparen\@@enparen(#1)\egroup} \def\@@enparen#1{\bgroup\let\enparen\@@@enparen[#1]\egroup} \def\@@@enparen#1{\bgroup\let\enparen\@enparen\{#1\}\egroup} \let\enparen\@enparen ...


13

Maybe nested definitions: \documentclass{article} \newcommand{\enparent}[1]{{% \def\enparent##1{{\def\enparent####1{\{####1\}}[##1]}}(#1)% }} \begin{document} \noindent \enparent{My outer layer \enparent{my inner lever \enparent{my innermost level}}}\\ \enparent{My outer layer \enparent{my inner lever \enparent{my innermost level}}} \end{document}


13

You can make _ math active: \AtBeginDocument{ \catcode`_=12 \begingroup\lccode`~=`_ \lowercase{\endgroup\let~}\sb \mathcode`_="8000 } MWE: \documentclass{article} \usepackage[T1]{fontenc} \AtBeginDocument{ \catcode`_=12 \begingroup\lccode`~=`_ \lowercase{\endgroup\let~}\sb \mathcode`_="8000 } \begin{document} a_b $a_b$ \end{document} ...


12

Could be tweaked a bit more but.... \documentclass{scrartcl} \usepackage{tipa,graphics} \makeatletter \providecommand\xloweraccent{\@ifnextchar[{\lower@accent x\empty}% {\lower@accent x\empty[\z@]}} \def\brak#1{\xloweraccent{% \raisebox{-.3ex}{\resizebox{!}{.6ex}{\bfseries(}}% {\fontencoding{T3}\selectfont\char12}% ...


12

I personally consider Herbert Voss' mathmode document one of the definitive guides to mathmode. He covers the differences in Section 9, pg. 27 If you've installed TeX Live, you can access it on your machine using texdoc mathmode, in MiKTeX you will get it with texdoc voss-mathmode.


10

Thank you very much, David Carlisle! After learning how it works from your answer, I have been able to make my own tweaks: Instead of the brackets and the x, I am using the tipa characters that are produced with \textsublhalfring, \textsubrhalfring and \textovercross respectively. I also forced the bracketed diacritics to be always upright, so the kerning is ...


10

I seem to remember having something to do with that answer :). The short answer to your query is that there is no a priori way of deciding based on a random macro whether it's "math mode" or "text mode", since of course a macro could be named anything. It is possible (see this question) to write a test that detects whether a macro enters math mode. ...


10

On the last line: Lines 14, 15 in vc_value are bottlenecks you use the underscore without escaping it. This is what causes the error. The underscore is used to specify subscript in mathmode, so an error occurs when you try to use it like this. Just escape it as: Lines 14, 15 in vc\_value are bottlenecks and you're good to go. You might find some ...


9

Have a look at the ideas at The baseline problem corrected. They have been incorporated into mathTeX vertical alignment if you want to use mathTeX to create the images.


8

FWIW, in ConTeXt the special characters _ and ^ do not need to be escaped in text mode and work correctly in math mode. ConTeXt table and math alignment macros do not use & as an alignment marker, so & also does not need to be escaped in text mode.


8

AFAIK there is no \ensuretext because a simple \hbox or \mbox is enforcing text mode already. However, if you need automatic scaling for subscripts etc. then use Leo's answer which handles this. BTW there is the \ifmmode switch to test if you are in mathmode. It is used by e.g. \text.


8

I agree with ArTourter that you are probably better off simply choosing a font that has an appropriately sized underscore character. However, here's a hack using the relsize package that allows you to scale the underscore character to your liking. It would also be possible to use the underscore character only from a different font, but I'm not sure that the ...


7

To have a functionality similar to amsmath's \text, but without loading any of the AMS-family packages, you can simply copy into your preamble a modification of the code for \text from amstext.sty: \documentclass{article} \makeatletter \DeclareRobustCommand{\text}{% \ifmmode\expandafter\text@\else\expandafter\mbox\fi} \let\nfss@text\text ...


7

We need to have enough space for the longest of the two sub-/superscripts. For that we can calculate the maximum of both sub-/superscripts' widths and make a box as wide as the maximum: \documentclass{article} \usepackage{fixltx2e} % For \textsubscript \makeatletter \newcommand{\textsubsuperscript}[2]{% \begingroup ...


6

It does, but you need to know what you're doing. Notation differs across users and most certainly disciplines, and therefore the typesetting is left up to the user, rather than (La)TeX. If you which to use certain commands conveniently in text and math mode, you have to provide your own rules. An elementary example: \documentclass{article} ...


6

As Ryan mentioned there is no real way to tell, however you can peek at the definition and normally there are enough clues to tell: \documentclass{article} \begin{document} \texttt{\meaning\alpha} \show\alpha \end{document} You can use either \meaning to typeset the result or \show to see them in the console. The \texttt in MWE is just to get the right ...


6

without using any package. \documentclass{article} \begin{document} $Math - \mathrm{upright} - \textrm{upright} - \mbox{upright}$ \par\Large $A^{\mathrm{text}}_{\mathrm{text}}$ \quad $A^{\textrm{text}}_{\textrm{text}}$\quad $A^{\mbox{text}}_{\mbox{text}}$ \quad $A^{\textnormal{text}}_{\textnormal{text}}$ \end{document} However, for text one ...


6

The upright form can easily be based from the “2”. The italic one is a bit tricky. I don't think you can avoid creating your own character here or putting more graphical effort in it. If you had that glyph in some kind of digital form you could include it in your document (License!). Code \documentclass{scrartcl} \usepackage[ngerman]{babel} ...


4

The overfull \hbox message is only a warning (TeX complains that a line is too long). The error results from using the _ (underscore) character -- see this minimal example: \documentclass{article} \begin{document} Lines 14, 15 in vc_value are bottlenecks \end{document} Reason: You can't use _ in normal text -- TeX uses the underscore in math mode to ...


4

Note that dvipng can determine the baseline for you, as long as you activate the 'preview' style. Here are the exact steps you need: Put \usepackage[active,textmath]{preview} in your LaTeX header Run LaTeX to get a dvi file, (eg myfile.dvi) Run dvipng -Ttight -D $MYDPI -depth myfile.dvi This last command will create a file myfile.png, and it will output ...


4

I would just create new commands for these "text-style" delimiters using \bigl and \bigr: \documentclass{article} \newcommand{\textbigl}[1]{$\bigl#1$\nobreak} \newcommand{\textbigr}[1]{\nobreak$\bigr#1$} \begin{document} Here is some regular text and then it is obvious that it might \textbigl(when factorizing~$e^{-2000t}$\textbigr) when you consider ...


4

It would be a bit fragile to do that in TeX: I'd do the replace with a regex in the editor as you suggest. (If you just wanted to make a ~ in text and a normal space in math that would be easier, but having it work in listings and verbatim would be harder) For example given \documentclass{article} \usepackage{amsmath} \begin{document} A new example here ...


3

You can emulate a cases environment for text mode using a \parbox or a tabular environment: \documentclass{article} \usepackage{amsmath} \newcommand\Text{text text text text text text text text text text text text text text text text text text text text text text text text text } \begin{document} \[ \left\lbrace\parbox{7cm}{\Text}\right. \] \[ ...



Only top voted, non community-wiki answers of a minimum length are eligible