1

I have this simple code:

\documentclass[10pt]{article}

% amsmath package, useful for mathematical formulas \usepackage{amsmath} % amssymb package, useful for mathematical symbols \usepackage{amssymb} \usepackage{changepage} % graphicx package, useful for including eps and pdf graphics % include graphics with the command \includegraphics \usepackage{graphicx} \usepackage{subfig} \usepackage{listings} \usepackage{caption}

% cite package, to clean up citations in the main text. Do not remove. \usepackage{cite}

\usepackage{color}

% Use doublespacing - comment out for single spacing %\usepackage{setspace} %\doublespacing

% Text layout \topmargin 0.0cm \oddsidemargin 0.5cm \evensidemargin 0.5cm \textwidth 16cm \textheight 21cm

% Bold the 'Figure #' in the caption and separate it with a period % Captions will be left justified

\usepackage[labelfont=bf,labelsep=period,justification=raggedright]{caption} \usepackage{amsfonts} \usepackage{t1enc} \usepackage{lastpage} \usepackage{fancyhdr} \usepackage{pdflscape} % Allow long tables to be split over multiple pages \usepackage{longtable}

\title{TEST}

\begin{document} \maketitle \section*{Equations}

\noindent Example Equation \begin{equation} E_x= 1-e^{-k_{time}t} \end{equation}

...

\texttt{E_x}

\end{document}

I receive "Missing $ inserted" on the \texttt{E_x}, but I know that \texttt{} function is used to produce a text-mode of what it has inside the {}. What am I wrong?

Zarko
  • 296,517
Smarcix
  • 11
  • 1
  • 1
    I think the underscore has to be inside math mode. \texttt is just for looks (text formatting) not for content modification (i.e. like $$). If you're looking to print "E_x" like that without transforming it you want the verbose environment or \verb!E_x! . – Plergux Mar 08 '21 at 16:18
  • 1
    you need \_ to get a _ in text – David Carlisle Mar 08 '21 at 16:37
  • unrelated but use k_{\mathrm{time}} the version you have will space t i m e like a product of variables not a word. – David Carlisle Mar 08 '21 at 16:38
  • Ty for the answers: I want to display "E_x", not the mathematical form "Ex" and in the https://www.tutorialspoint.com/tex_commands/texttt.htm I have supposed that texttt will be the correct function tu use. To be onest, I receive an error with "\texttt{\alpha}" too, so the problem is not the underscore, but the use of mathematical form in the \texttt, but, if I will understand correctly, \texttt function is used to display in textual form what it has inside the {}. I need to display the name of a matlab variable in textual form (this is my final purpose). Ty – Smarcix Mar 09 '21 at 08:04

1 Answers1

1

Try this:

\texttt{E\textsubscript{\_n}}

Nick B
  • 831
  • With \texttt{E\textsubscript{n}}, I have no errors, but I don't want in display "En" but "E_n", because in the original text I want to display the name of the variable that I have implemented in matlab (in the matlab lenguage). Any other suggestion? Ty – Smarcix Mar 09 '21 at 07:51
  • add a \ in front of the underscore in the line of code – Nick B Mar 09 '21 at 12:35
  • This solution works well, Ty! – Smarcix Mar 09 '21 at 15:18