5

The quotes in pseudocode currently look like this:

enter image description here

How can I get quotes that look more like a programming environment and less as if I just typed it with MS Word?

MWE

\documentclass{article}
\usepackage[pdftex,active,tightpage]{preview}
\setlength\PreviewBorder{2mm}

\usepackage[utf8]{inputenc} % this is needed for umlauts
\usepackage[ngerman]{babel} % this is needed for umlauts
\usepackage[T1]{fontenc}    % this is needed for correct output of umlauts in pdf
\usepackage{amssymb,amsmath,amsfonts} % nice math rendering
\usepackage{algorithm,algpseudocode}

\begin{document}
\begin{preview}
    This is a 'samle' with some "quotes".

    \begin{algorithm}[H]
        \begin{algorithmic}
            \State $a \gets \Call{map}{~}$
            \State $a['x'] \gets 42$
            \State $a["x"] \gets 1337$
        \end{algorithmic}
    \caption{Algorithmus von Stoer und Wanger}
    \label{alg:seq1}
    \end{algorithm}
\end{preview}
\end{document}

Related questions

The question was already answered for some other environments:

4

You can have the straight quotes, provided you use some tricks.

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

\usepackage{textcomp}
\usepackage{amssymb,amsmath,amsfonts}
\usepackage{algorithm,algpseudocode}
\usepackage{etoolbox} % for the trick

% setup algorithmic to use straight quotes
\AtBeginEnvironment{algorithmic}{\useupquotes}

% define the command that activates the quotes and redefines them
\newcommand{\useupquotes}{%
  \begingroup\lccode`\~=`\'\lowercase{\endgroup\let~}\algoupquote
  \begingroup\lccode`\~=`\"\lowercase{\endgroup\let~}\algoupquotes
  \catcode`\'=\active\catcode`\"=\active
}

% Customize here (\mbox is necessary because of math mode;
% if needed in subscripts, use \text instead)
\newcommand{\algoupquote}{\mbox{\textquotesingle}}
\newcommand{\algoupquotes}{\mbox{\char`\"}}

\begin{document}
Look at Algorithm~\ref{some} for seeing the quotes.

\begin{algorithm}[htp]
\begin{algorithmic}
\State $a['x'] \gets 42$
\State $a["x"] \gets 1337$
\end{algorithmic}
\caption{Some algorithm}\label{some}
\end{algorithm}
\end{document}

enter image description here

2

Here's the active character approach, also using textcomp.

\documentclass{article}
\usepackage[pdftex,active,tightpage]{preview}
\setlength\PreviewBorder{2mm}

\usepackage[utf8]{inputenc} % this is needed for umlauts
\usepackage[ngerman]{babel} % this is needed for umlauts
\usepackage[T1]{fontenc}    % this is needed for correct output of umlauts in pdf
\usepackage{amssymb,amsmath,amsfonts} % nice math rendering
\usepackage{algorithm,algpseudocode}
\usepackage{textcomp}
\let\svalgorithm\algorithm
\catcode`'=\active
\catcode`"=\active
\def\quoteactive{\catcode`'=\active\def'{\makebox{\textquotesingle}}}
\def\qquoteactive{\catcode`"=\active\def"{\makebox{\textquotedbl}}}
\catcode`'=12
\catcode`"=12
\def\algorithm{\quoteactive\qquoteactive\svalgorithm}

\begin{document}
\begin{preview}
    This is a 'sample' with some "quotes"{} or ``quotes''.

    \begin{algorithm}[H]
        \begin{algorithmic}
            \State $a \gets \Call{map}{~}$
            \State $a['x'] \gets 42$
            \State $a["x"] \gets 1337$
        \end{algorithmic}
    \caption{Algorithmus von Stoer und Wanger}
    \label{alg:seq1}
    \end{algorithm}
Restored? ' and ", ``quotations'' or `quotations'
\end{preview}
\end{document}

enter image description here

  • Which is exactly the same approach I used. – egreg Oct 2 '14 at 20:03
  • @egreg Did you post first? If so, I'll remove mine. – Steven B. Segletes Oct 2 '14 at 22:07
  • Don't; it's a different implementation, without etoolbox. – egreg Oct 2 '14 at 22:08
  • Well, I take it as a compliment to be accused of thinking like @egreg ;^) – Steven B. Segletes Oct 2 '14 at 22:09
1

You could probably make the quotes active, but I suggest wrapping them in a macro (a reference would be given in Straight quotes?):

enter image description here

\documentclass{article}

\usepackage[utf8]{inputenc} % this is needed for umlauts
\usepackage[ngerman]{babel} % this is needed for umlauts
\usepackage[T1]{fontenc}    % this is needed for correct output of umlauts in pdf
\usepackage{textcomp}
\usepackage{amssymb,amsmath,amsfonts} % nice math rendering
\usepackage{algorithm,algpseudocode}

\makeatletter
\newcommand{\upquotetype}{}
\newcommand{\upquote@aux}[1]{\text{\upquotetype}#1\text{\upquotetype}}
\newcommand{\upquotesingle}{\renewcommand{\upquotetype}{\textquotesingle}\upquote@aux}
\newcommand{\upquotedouble}{\renewcommand{\upquotetype}{\textquotedbl}\upquote@aux}

\begin{document}
This is a 'sample' with some "quotes".

\begin{algorithm}[H]
  \begin{algorithmic}
    \State $a[\upquotesingle{x}] \gets 42$
    \State $a[\upquotedouble{x}] \gets 1337$
  \end{algorithmic}
  \caption{Some algorithm}
\end{algorithm}
\end{document}

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.