1

I am building an automatic password generator producing a pdf. I am having troubles in typesetting the backticks, how can I print a backtick in inside a \texttt?

EDIT: my mac spell checker changed backtick to backpack in the title, now I corrected it

  • \texttt{`abc} or do you mean you are looking for a straighter left quote? – David Carlisle Mar 13 '18 at 23:37
  • I would like to print a real backtick – Nisba Mar 13 '18 at 23:40
  • 1
    Please define `real' – JPi Dec 17 '18 at 15:26
4

enter image description here

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage{textcomp}
\begin{document}

\texttt{`abc \textasciigrave abc}

\end{document}
2

I have found also that I can also use \`{}

0

For those using the listings package instead of just \texttt, you can add the following line to either \lstdefinelanguage or \lstset:

literate={`}{\textasciigrave}1,

For example, here is my \lstdefinelanguage for PVS:

\usepackage[dvipsnames]{xcolor}
\definecolor{darkblue}{rgb}{0,0,0.6}
\definecolor{darkgreen}{rgb}{0,0.5,0}
\definecolor{darkred}{rgb}{0.6,0,0}
\usepackage{listings}
\lstdefinelanguage{pvs}{
  basicstyle=\small\ttfamily,
  keywordstyle=\color{darkblue}\bfseries,
  morekeywords={and,andthen,array,assuming,assumption,auto_rewrite,auto_rewrite+,auto_rewrite-,axiom,begin,but,by,cases,challenge,claim,closure,cond,
                conjecture,containing,conversion,conversion+,conversion-,corollary,datatype,else,elsif,end,endassuming,endcases,endcond,endif,endtable,exists,exporting,
                fact,false,forall,formula,from,function,has_type,if,iff,implies,importing,in,inductive,judgement,lambda,law,lemma,
                let,library,macro,measure,nonempty_type,not,o,obligation,of,or,orelse,postulate,proposition,recursive,sublemma,subtypes,subtype_of,
                table,then,theorem,theory,true,type,type+,var,when,where,with,xor},
  sensitive=false,
  literate={`}{\textasciigrave}1,
  commentstyle=\color{darkgreen},
  morecomment=[l]{\%},
  stringstyle=\color{darkred},
  morestring=[b]",
}

If you're using a known language (e.g., C), you can just do:

\lstset{% 
  language=C,
  literate={`}{\textasciigrave}1,
}

This will use the substitution suggested by David Carlisle everywhere you use the backtick in your code listing. I then define a command called \code for doing in-line code using the listings package:

\newcommand{\code}[1]{\lstinline{#1}}

So I can then just use \code{`abc} to get the result you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.