# How to display $in listings Latex TeX - LaTeX Asked by vrige on September 5, 2020 I need to write three different programming languages: C#, R and TensorFlow. TensorFlow has the keyword tf$ and i would like to have it as keyword in my latex file, but i have got an error.

documentclass{article}
usepackage[utf8]{inputenc}

usepackage{xcolor}
usepackage{listings}
usepackage{accsupp}
newcommand*{noaccsupp}[1]{BeginAccSupp{ActualText={}}#1EndAccSupp{}}

lstset{%
literate=
{$}{{${$}}}1 } lstdefinestyle{Common} { basicstyle=scriptsizettfamilynull, numbers=left, numbersep=1em, frame=single, framesep=fboxsep, framerule=fboxrule, xleftmargin=dimexprfboxsep+fboxrule, xrightmargin=dimexprfboxsep+fboxrule, breaklines=true, breakindent=0pt, tabsize=5, columns=flexible, showstringspaces=false, captionpos=b,% or t for top (default) abovecaptionskip=0.5smallskipamount, % there is also belowcaptionskip } lstdefinestyle{Mathematica} { style=Common, language={Mathematica}, alsolanguage={[LaTeX]TeX}, morekeywords= { Animate, AnimationRunning, }, keywordstyle =color{blue}, } lstdefinestyle{CSharp} { style=Common, language={[Sharp]C}, alsolanguage={[LaTeX]TeX}, morekeywords= { % }, keywordstyle =color{blue}, } lstdefinestyle{R} { style=Common, language={R}, alsolanguage={[LaTeX]TeX}, morekeywords= { % }, keywordstyle =color{blue}, } lstdefinestyle{TensorFlow} { alsoletter = {$},
style=Common,
language={[Sharp]C},
alsolanguage={[LaTeX]TeX},
morekeywords=
{
tf$}, keywordstyle =color{blue}, } lstnewenvironment{Mathematica} {lstset{style=Mathematica}} {} lstnewenvironment{CSharp} {lstset{style=CSharp}} {} lstnewenvironment{R} {lstset{style=R}} {} lstnewenvironment{TensorFlow} {lstset{style=TensorFlow}} {} title{...} author{...} date{August 2020} begin{document} maketitle section{Introduction} begin{R} fib <- function(n) { if (n < 2) n else fib(n - 1) + fib(n - 2) } fib(10) # => 55 end{R} begin{TensorFlow} sess$run(TF_up81a)
tf$logical_not() end{TensorFlow} end{document}  ## 2 Answers Using mathescape = true, but the keyword is not reconize. documentclass{article} usepackage[utf8]{inputenc} usepackage{xcolor} usepackage{listings} usepackage{accsupp} usepackage{amsmath} newcommand*{noaccsupp}[1]{BeginAccSupp{ActualText={}}#1EndAccSupp{}} lstset{% literate= {$}{{${$}}}1
}

lstdefinestyle{Common}
{
basicstyle=scriptsizettfamilynull,
numbers=left,
numbersep=1em,
frame=single,
framesep=fboxsep,
framerule=fboxrule,
xleftmargin=dimexprfboxsep+fboxrule,
xrightmargin=dimexprfboxsep+fboxrule,
breaklines=true,
breakindent=0pt,
tabsize=5,
columns=flexible,
showstringspaces=false,
captionpos=b,% or t for top (default)
abovecaptionskip=0.5smallskipamount,   % there is also belowcaptionskip
}
lstdefinestyle{Mathematica}
{
style=Common,
language={Mathematica},
alsolanguage={[LaTeX]TeX},
morekeywords=
{
Animate,
AnimationRunning,
},
keywordstyle =color{blue},
}
lstdefinestyle{CSharp}
{
style=Common,
language={[Sharp]C},
alsolanguage={[LaTeX]TeX},
morekeywords=
{
%
},
keywordstyle =color{blue},
}
lstdefinestyle{R}
{
style=Common,
language={R},
alsolanguage={[LaTeX]TeX},
morekeywords=
{
%
},
keywordstyle =color{blue},
}
lstdefinestyle{TensorFlow}
{
% alsoletter = {$}, % escapechar= {$},
mathescape = true,
style=Common,
language={[Sharp]C},
alsolanguage={[LaTeX]TeX},
morekeywords=
{
tf$mathdollar$%
},
keywordstyle =color{blue},
}

lstnewenvironment{Mathematica}
{lstset{style=Mathematica}}
{}
lstnewenvironment{CSharp}
{lstset{style=CSharp}}
{}
lstnewenvironment{R}
{lstset{style=R}}
{}
lstnewenvironment{TensorFlow}
{lstset{style=TensorFlow}}
{}

title{...}
author{...}
date{August 2020}

begin{document}

maketitle

section{Introduction}

begin{R}
fib <- function(n) {
if (n < 2)
n
else
fib(n - 1) + fib(n - 2)
}
fib(10) # => 55
end{R}

begin{TensorFlow}
sess$mathdollar$run(TF_up81a)
$color{blue}rm{tf}mathdollar$logical_not()
end{TensorFlow}

end{document}


Answered by flav on September 5, 2020

By using in the front of \$ symbol.

Answered by Anton Vrdoljak on September 5, 2020

## Related Questions

### Moved from TexLive 2018 to 2020 and now I’m getting countless font errors

0  Asked on June 26, 2021 by gil-williams

### kpfonts changes appereance of textcomp symbols

4  Asked on June 26, 2021 by david-woitkowski

1  Asked on June 26, 2021

### GIF in XeLaTeX PDF using animate

0  Asked on June 26, 2021 by alayt-abraham

### babel 3.42 (and later?): “nohyphenation” and languages that use “zerohyph.tex” aren’t recognized

1  Asked on June 26, 2021 by pglpm

### Beamer notes “show notes on second screen” option does not work

1  Asked on June 26, 2021

### Removing bibliography fields

1  Asked on June 26, 2021 by plr

### Wedge product symbol (exterior/alternating product)

4  Asked on June 26, 2021

### How to make add a square box inside another?

1  Asked on June 26, 2021 by max-lab

### The format of if-else in the function is wrong

1  Asked on June 26, 2021

### No section numbers, but still have PDF bookmarks with hyperref

7  Asked on June 26, 2021

### Cannot include my .bib content into my .tex document

1  Asked on June 26, 2021 by john-campbell

### Reduce horizontal gap between legend and pie chart

1  Asked on June 25, 2021 by yogesh-sharma

### {}edef [email protected] {[email protected] error when citing same bibtex entry in externaldocument

1  Asked on June 25, 2021 by grobber

### Problem with writing in Hebrew in LyX

0  Asked on June 25, 2021 by alor-k

### Customized numeration in algorithmic

1  Asked on June 25, 2021 by leo96

### Tikz fit inner sep seperate values for all 4 directions

3  Asked on June 25, 2021 by d4rty

### What column of a tabular is a cell in?

1  Asked on June 25, 2021

### ETbb conflict with tufte

1  Asked on June 25, 2021 by otaviolb

### PGFPlots – Using “smooth” doesnt render smooth curves, but “samples” doesnt work either

0  Asked on June 25, 2021 by harith