I am trying to write programming code in latex using the verbatim environment, but when I write
\begin{verbatim}
char ch = 'x';
\end{verbatim}
then the ' -characters around x are displayed incorrectly (they look "curly"). How can I fix this problem?
Load the upquote package to fix this issue in verbatim mode.
If you want straight quotes in monospaced text mode (e.g., \texttt{...}), or indeed in any other font, then you can use the \textquotesingle command defined in the textcomp package:
\documentclass{article}
\usepackage{upquote,textcomp}
\begin{document}
\newcommand\upquote[1]{\textquotesingle#1\textquotesingle}
\verb|'c'| \texttt{\upquote{h}}
\textsf{\upquote{h}} \upquote{h}
\end{document}
This will work well for fonts in any encoding rather than depending on a specific glyph slot (such as \char13 in the default OT1 encoding).
Adding \usepackage{upquote} to my preamble was sufficient.
Perhaps older versions of LaTeX or upquote required more work.
I have
What is wrong?
New
If you want to get something like this
write
\makeatletter
\let \#sverbatim \#verbatim
\def \#verbatim {\#sverbatim \verbatimplus}
{\catcode`'=13 \gdef \verbatimplus{\catcode`'=13 \chardef '=13 }}
\makeatother
For displaying source code, you might consider using the listings package; it is quite powerful and offers an option to display “straight” quotation marks.
If you're seeing curly single right quotes in a verbatim environment, then the single right quote in your typewriter font is curly, and that's the correct one to use for what you're doing (which I assume is displaying some C code).
\textsf{``} and \textsf{''} come pretty close to straight quotes. No need for using any special packages.
This is what I got from another source, and this works.
Use `` to start the double quotes (this symbol is below ~ symbol on our keyboard)
Use '' to close the double quotes (this symbol is below the " symbol on our keyboard)
So, `` quote double, unquote double''
Same goes for single quotes, `quote single, unquote single'
Related
csquotes doesn't work in this case, maybe because I'm using a custom command:
\documentclass[12pt, letter, american]{article}
\usepackage[american]{babel}
\usepackage[autopunct,style=american]{csquotes}
\newcommand{\qq}[1]{\textquote{#1}}
\begin{document}
This is an \qq{example}.
\end{document}
\qq will not move the trailing period into the quotation, e.g. This is an \qq{example}. will still yield This is an “example”. I have written a book using \qq and would like to change the quotation styles to one which moves periods and colons into the quotes. Is there a safe way to achieve this automatically? Maybe a package different from csquotes? The only solution I've found on the net so far didn't work with spacing correctly.
See the csquotes documentation, section 9.2:
\documentclass[12pt]{article}
\usepackage[american]{babel}
\usepackage[autopunct,style=american]{csquotes}
\renewcommand{\mktextquote}[6]{#1#2#4#5#3#6}
\newcommand{\qq}[1]{\textquote{#1}}
\begin{document}
This is an \qq{example}.
\end{document}
I'm using latex to model a few functions using Z-Notation, however, I'm having issues showing a string for output. In this reduced example code, the text in the quotes has a different formatting from what I would expect. What can I use to keep the formatting the text inside the quotes to be the same in the code snippet?
Edit: The overDraftMessage should be messageOutput, missed changing this when creating a reduced example.
\documentclass{article}
\usepackage{oz} % oz or z-eves or fuzz styles
\begin{document}
\begin{schema}{function}
messageOutput!: $STRING$ \\
\where
messageOutput! = ''Output looks strange.'' \\
\end{schema}
\end{document}
Solution from #lburski works, but tilde is not for this purpose. It should be used to make hard space (non-breaking space). To write space in whitespace insensitive environments, you need to escape it - write backslash before every space: ''Output\ looks\ strange''.
If you want a space between the words on your string ''Output looks strange.'' then try putting a tilde '~' between those words. So you string ends up being ''Output~looks~strange.''
Does anyone know how to make (nice looking) double bracket multiset notation in LaTeX, i.e something like (\binom{n}{k}) where there are two outer brackets instead of 1 as in binomial? You can see an example of what I mean in http://en.wikipedia.org/wiki/Multiset under the heading "Multiset coefficients" with the double brackets.
In Wikipedia they typeset it as:
\left(\!\!{n\choose k}\!\!\right)
but although this works well for LaTeX in maths mode, with inline equations the outer bracket becomes much larger than the inner bracket.
I have also tried using
\genfrac{((}{))}{0pt}{}{n}{k}
but it has an error with the double brackets.
I am using \binom as well in my document, so I would like the bracket sizes to be similar for \binom and \multiset.
You can explicitly specify the size of the brackets via
\big( \Big( \bigg( or \Bigg(
Then use \! for negative space to get the brackets closer to each other.
One can use the e-TeX \middle command as follows:
\newcommand{\multibinom}[2]{
\left(\!\middle(\genfrac{}{}{0pt}{}{#1}{#2}\middle)\!\right)
}
This assumes that you are using the AMSmath package. If not, replace \genfrac with the appropriate construct using \atop.
(Of course this is a hack: the proper solution would be scalable glyphs for the doubled parenthesis, but I can't find any fonts that provide it.)
I'm surprised it wasn't googlable either, so I'll provide a solution here for posterity's sake.
It is also possible to define two different new commands, using \tbinom and \dbinom (section 4.11.2 of the User's Guide for the amsmath Package):
\documentclass{article}
\usepackage{amsmath}
\newcommand{\inlinebnm}[2]{\ensuremath{\big(\!\tbinom{#1}{#2}\!\big)}}
\newcommand{\displybnm}[2]{\bigg(\!\!\dbinom{#1}{#2}\!\!\bigg)}
\begin{document}
Text $\inlinebnm{a}{b}$ text. %% inline
Text \inlinebnm{a}{b} text. %% inline (also ok thanks to ensuremath)
\[
\displybnm{a}{b} %% display-style
\]
\end{document}
I am writing a document in spanish, and I'm trying to add 'í' to the word
Montréal.However if I put the i like this: \'{e} in the code below, I just get a space instead of the é. Why is this not working?
\begin{tabbing}%
\hspace{2.3in}\= \hspace{2.6in}\= \kill % set up two tab positions
{\bf Engineer}\> Panagro S.A.\> Summers 2004-2010\\
\>Montréal, Colombia
\end{tabbing}\vspace{-15pt}
Also I might add that when I try putting Montréal outside of the tabbing block, it works fine.
Ted
Tabbing environment
Some of the accent marks used in running text have other uses in the tabbing environment. In that case they can be created with the following command:
\a' for an acute accent
\a` for a grave accent
\a= for a macron accent
source: LaTeX/Accents at Wikibooks
Related question on tex.stackexchange with a great solution to accented characters.
Save your file as UTF-8 and put
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
in your preamble.
Then you can just type the characters normally into your source file.
Or, use XeLaTeX which accepts UTF-8 input natively. In that case you need to add
\usepackage{fontspec}
to your preamble.
If your text editor doesn't support UTF-8 encoded files, you should probably get another editor. But if you're stuck with one, you can also use:
\usepackage[latin1]{inputenc} % for PCs
\usepackage[applemac]{inputenc} % for Macs
and save the files in the default encoding for your machine.
Thanks to Alan Munn for the solution!
i have a little question about the verbatim environment in latex.....
my problem is how can i write "\end{verbatim}" inside of a verbatim environment, it supposed that everything inside a verbatim is written just like it looks but this is the string to end the environment, so how can i do this?
\\end{verbatim}
Should do it by making the initial \ into a literal backslash.
I think it might be impossible in a verbatim environment -- at least, that's what Lamport says in the LaTeX book (first paragraph on pg. 64). However, you can do it with the \verb command: \verb+\end{verbatim}+ works just fine (and in fact, you can use any character instead of + as long as you make them match).
That said, the listings package is smart enough to have an escape character. For example,
\begin{lstlisting}[escapechar=+]
+\verb!\end{lstlisting}!+
\end{lstlisting}
does exactly what you're looking for. (Again, pick a different character than + if you're already using that for something else.)
Use the fancyvrb package instead of the default verbatim package.
Craig's answer is good. Alternatively, \expandafter\string\csname end{verbatim}\endcsname.
These solutions won't linebreak nicely: fixing this is fiddly.
I have a simpler solution. Write a non-breaking space, in Emacs it's C-x 8 SPC (Windows, though I haven't tried it is Alt+0160 (on numeric keypad)). So, you can do this:
\begin{verbatim}
\_end{verbatim}
\end{verbatim}
where the first \end{verbatim} has this "_", the non-breaking character.
Here is my method, thanks #S.Lott for his advice.
If you want to write \end{verbatim} in the verbatim environment, you have to using another 'verbatim' layer to nest your code (this is where fancyvr package comes to play). Here it is:
\documentclass{article}
\usepackage{fancyvrb}
\begin{document}
Some text here
\begin{Verbatim} % note 'uppercase V' in verbatim
\begin{verbatim}
Code example
\end{verbatim}
\end{Verbatim}
\end{document}