TransWikia.com

How to preserve tabs in semiverbatim?

TeX - LaTeX Asked by fomin on August 27, 2020

I have the following slide:

documentclass{beamer}
beamertemplatenavigationsymbolsempty
setbeamertemplate{frametitle}[default][center]
usepackage[many]{tcolorbox}
newcommand{Proc}[1]{textsc{#1}}
newcommand{Var}[1]{ensuremath{textcolor{varcolor}{#1}}}

newcommand{Com}[1]{textcolor{comcolor}{#1}}
newcommand{Blue}[1]{textcolor{varcolor}{#1}}
definecolor{varcolor}{RGB}{15,122,183}

definecolor{comcolor}{RGB}{10,161,119}
definecolor{framecolour}{HTML}{009980}

date{}
begin{document}
begin{frame}[fragile]{Finding the majority}
    begin{center}
    begin{tcolorbox}[text width=5.5cm]
begin{semiverbatim}
Proc{Majority}(Blue{x_1, x_2, dots, x_n})

Com{initialise} item Var{m}
Com{initialise} counter Var{c=0} 
for each item Var{x_i} in sequence 
    if Var{x_i} == Var{m}
        Var{c} = Var{c} + 1   
    else 
        if Var{c} == 0
            Var{m} = Var{x_i}
            Var{c} = Var{c} + 1
        else
            Var{c} = Var{c} - 1
end{semiverbatim}
    end{tcolorbox}
end{center}
end{frame}
end{document}

Unfortunately none of the indentation in the semiverbatim part is shown.

enter image description here

Why is this?

As a secondary question, is there way to get the subscripts in x_1, x_2, dots, x_n to work?

EDIT

It seems the problem only appears if I use tabs. If you replace them with spaces it works fine. If you copy and paste the LaTeX from this question it seems you will get spaces so you will need to convert them back to tabs to be able to reproduce the problem.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP