LaTeX, tildes and verbatim mode

感情迁移 提交于 2019-12-12 10:55:24

问题


Following on from this question, I'm totally stumped on getting LaTeX to give me a tilde when I'm in verbatim mode. It has to be a tilde because it's the type of a function!

sig symm : (Board, [(Int, Int)]) ~> Bool

Standard methods for displaying a tilde are printed verbatim, of course..

Any suggestions?

An edit to clarify: Typing a ~ in verbatim mode gives an accent above a blank space. I'm after a tilde as it appears at the beginning of this sentence.


回答1:


If there are some characters that do not occur in your input, you can use fancyvrb and its commandchars option to insert TeX commands within verbatim text:

\documentclass{article}
\usepackage{fancyvrb}
\begin{document}
\newcommand{\mytilde}{$\sim$}
\begin{Verbatim}[commandchars=\\\{\}]
sig symm : (Board, [(Int, Int)]) \mytilde> Bool
\end{Verbatim}
\end{document}

See the documentation of fancyvrb for more.




回答2:


Perhaps you should look at: LaTeX package to do syntax highlighting of code in various languages which has suggestions for typesetting code...


I assumed that listing would do it for you, but failing that alltt and fancyvrb are alternatives to verbatim. See this search on CTAN for other possibilities.




回答3:


If you are using listing command, you can set the tilde to be literal. Likt this.

\documentclass
\usepackage{listings}
\lstset{
    literate={~} {$\sim$}{1} % set tilde as a literal (no process)
}

\begin{document}

\begin{lstlisting}
~
\end{lstlisting}

\end{document}



回答4:


\begin{verbatim}
~
\end{verbatim}


来源:https://stackoverflow.com/questions/682201/latex-tildes-and-verbatim-mode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!