Text FormattingLyX: Math Code in Text Statement

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
topsquark
Posts: 71
Joined: Wed Oct 05, 2022 10:30 pm

LyX: Math Code in Text Statement

Post by topsquark »

I am writing up a short MathJax introduction and ran into a strange problem. I want to make a table where the first column is the symbol and the second column is the LaTeX code for it. Here's the code

Code: Select all

$\begin{array}{|c|c|}
     \hline
     \text{Symbol} & \text{Code} \\
     \hline
     + & + \\
     - & - \\
     *  &  * \\
     \cdot & \text{ \cdot } \\
     \times & \text{ \times } \\
     / & / \\
     \div & \text{ \div } \\ 
     \hline
\end{array}$
When this is run, notice the line \text{ \cdot } just gives the compiled \cdot, not the text \cdot.

**Note: In LyX it seems to just go ahead and compile \cdot. Here it won't do \text{ \cdot } at all, apparently.

How can I fix this?

Thanks!

-Dan

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
MjK
Posts: 89
Joined: Fri Jan 28, 2022 6:09 pm

LyX: Math Code in Text Statement

Post by MjK »

Without Infominimal working example I can tell you only, that \text usually is a command from amsmath to print text (with the current text font attributes) inside math. So it makes absolutely no sense to put math code like \cdot or \times inside \text. Maybe you want to show the verbatim code. In this case, you should use, e.g., \verb|\cdot|. See a LaTeX introduction for more information about \verb and the amsldoc for more information about \text.

Note also: MathJax is not LaTeX. So questions about MathJax would be mostly off-topic.
My main topics are KOMA-Script and other questions related to my packages. If I reply to any other topic or if you've not yet added a minimal working example, please do not expect any further response. And please don't forget to tag examples as code.
topsquark
Posts: 71
Joined: Wed Oct 05, 2022 10:30 pm

LyX: Math Code in Text Statement

Post by topsquark »

MjK wrote:Without Infominimal working example I can tell you only, that \text usually is a command from amsmath to print text (with the current text font attributes) inside math. So it makes absolutely no sense to put math code like \cdot or \times inside \text. Maybe you want to show the verbatim code. In this case, you should use, e.g., \verb|\cdot|. See a LaTeX introduction for more information about \verb and the amsldoc for more information about \text.

Note also: MathJax is not LaTeX. So questions about MathJax would be mostly off-topic.
I'm sorry, maybe I wasn't clear enough. I'm writing a MathJax tutorial in LyX. I'm not writing it in MathJax.

I would love to provide a working example. But I can't figure out how to make one!

I looked at the amsmath package. (Thank you, by the way, I hadn't thought to include that in what is, essentially, a text document.) It's recommending \textrm{ \cdot }. But it does the same thing in LyX.

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\begin{array}{|c|c|}
     \hline \\
     \textrm{Symbol} & \textrm{Code} \\
     \hline
     + & + \\
     - & - \\
     *  &  * \\
     \cdot & \textrm{\cdot} \\
     \times & \textrm{\times} \\
     / & / \\
     \div & \textrm{\div} \\ 
     \hline
\end{array}$
\end{document}
From the Preview panel on this site it appears that the system is expecting the \cdot should be inside math tags, which is why it won't render. If you like:

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\begin{array}{|c|c|}
     \hline \\
     Symbol & Code \\
     \hline
     + & + \\
     - & - \\
     *  &  * \\
     \cdot & \textrm{$\cdot$} \\
     \times & \textrm{$\times$} \\
     / & / \\
     \div & \textrm{$\div$} \\ 
     \hline
\end{array}$
\end{document}
This is the same as the output I'm getting from LyX using the \textrm{ } code without the dollar signs.

-Dan
User avatar
MjK
Posts: 89
Joined: Fri Jan 28, 2022 6:09 pm

LyX: Math Code in Text Statement

Post by MjK »

Once again: It is not absolutely not clear, what you want. As already told: If you want to show the result of, e.g., \times using \textrm would not make sense, because \textrm does not influence math mode and \times requires math mode. But if you want to show the code, you need \verb, e.g.

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{tabular}{|c|c|}
     \hline
     Symbol & Code \\
     \hline
     $+$ & + \\
     $-$ & - \\
     $*$ &  * \\
     $\cdot$ & \verb|\cdot| \\
     $\times$ & \verb|\times| \\
     $/$ & / \\
     $\div$ & \verb|\div| \\ 
     \hline
\end{tabular}
\end{document}
or maybe

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\begin{array}{|c|c|}
     \hline
     \text{Symbol} & \text{Code} \\
     \hline
     + & + \\
     - & - \\
     *  &  * \\
     \cdot & \verb|\cdot| \\
     \times & \verb|\times| \\
     / & / \\
     \div & \verb|\div| \\ 
     \hline
\end{array}$
\end{document}
See a LaTeX introduction for more information about text mode vs. math mode, \textrm vs. \mathrm, and about verbatim material.

And please always explain exactly the expected printing. Always ask yourself: What does someone need to solve my problem, if he or she cannot see into my brain?
My main topics are KOMA-Script and other questions related to my packages. If I reply to any other topic or if you've not yet added a minimal working example, please do not expect any further response. And please don't forget to tag examples as code.
Post Reply