Tag Info

Hot answers tagged


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 ...


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}}$% } ...


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 ...


$-9$ Minus nine is a number, so you should type the whole number in a single mode, in this case the math mode. If you can find a minus sign in text font, typing the sign and nine both in text mode is acceptable depend on the context.


Option C \documentclass{article} \usepackage{textcomp} \begin{document} \textminus 9 \end{document} This produces a legit minus sign.


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}


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 ...


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 ...


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.


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 ...


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} ...


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 ...


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}


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.


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}% ...


The accent command here is \v, so you want Ku\v{c}inskas. You could of course use UTF-8 input and either inputenc with pdfLaTeX or a UTF-8 capable engine (XeLaTeX/LuaLaTeX).


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 ...


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. ...


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 ...


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 ...


\catcode`\_=\active \def_{\relax\ifmmode\sb \else \_\fi}


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.


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.


For completeness' sake: the following characters are special to LaTeX and might not do what you expect: $ % ^ & _ { } ~ \ # (Thusly taken from lshort)


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.


With tikz \documentclass{article} \usepackage{tikz} \newcommand{\circledx}{% \begin{tikzpicture} \node[inner sep=0pt,outer sep=0pt] (a) {x}; \draw (a.center) circle (0.15ex); \end{tikzpicture} } \newcommand{\circledX}{% \begin{tikzpicture} \node[inner sep=0pt,outer sep=0pt] (a) {X}; \draw (a.center) circle (0.2ex); \end{tikzpicture} } ...


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 ...


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 ...


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} ...


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 ...

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