0

I want to be able to reproduce this environment within the context of exam correction.

One clue I found is the usage of the bclogo package.

https://ctan.org/pkg/bclogo

Howerver, I would like to include the highlighted Python code as seen here, and I want to include indentation lines and color them according to the scope (indentation level).

enter image description here

Coloring the lines of an algorithm:

enter image description here

Code of the colored Algorithm:

\pdfoutput=1
\usepackage[linesnumbered,titlenumbered,ruled,vlined,resetcount,algosection]{algorithm2e}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{color}

\begin{document}
\title{MWE}
\maketitle
\section{Algorithm}

\begin{algorithm}
    \caption{3-SAT in polynomial time}
    \label{alg:hs}
    \DontPrintSemicolon
    \KwIn{List of clauses}
    \KwOut{The clauses are satisfiable}
    \SetKwProg{Fn}{Function}{ is}{end}
    \Fn{\textsc{IsSatisfiable}($C$)} {
    
        \color{red} %<- my best attempt
        $k\gets 0$ \;
        \For {$i = 1$ \bf{to} $|C|$}
        {
            $c_i \gets $ $i$-th clause \;
            $L \gets$ list of literals of $c_i$ \;
            $k\gets f(k, L)$ \tcp{a miracle in polynomial time}
        }
        \color{black} %<- go back to color black
        
        \If {$k$ is even} {
            \Return true
        }
        \Else {
            \Return false
        }
        
    }
\end{algorithm}

\end{document}
2
  • 2
    Welcome. // Ok, to try and improve your code we have to A) retype it, B) guess about your preamble, C) hope for the best we met your situation. That's why responses will be more helpful when you post relevant code instead of code-screenshots. Kindly see here to create what we'd like to see here: tex.meta.stackexchange.com/questions/228/… . Thank you Commented Apr 22, 2024 at 16:36
  • 2
    @MS-SPO, Unfortunately I do not have the code of the image above as I'm trying to reproduce it. I only have the source code to the bottom one. I have added the source code. Please let me know if anything else is required in order to be able to reproduce it. Thank you. Commented Apr 22, 2024 at 16:44

1 Answer 1

2

For the Python code, here is a solution with the package piton which requires the use of LuaLaTeX (but no external program).

\documentclass{article}
\usepackage{geometry}
\usepackage{tikz}
\usepackage{piton}
\usepackage{lipsum}

\definecolor{bleupyth}{rgb}{0.2157,0.436,0.6172}
\definecolor{jaunpyth}{rgb}{1,0.8157,0.25}

\newcommand{\PythonLogo}{
\begin{tikzpicture}[scale=0.004]
  \begin{scope}[,yscale=-1]
    \fill[bleupyth] (41.1090,0.0000) .. controls (20.0860,0.0000) and
    (21.3980,9.1170) ..  (21.3980,9.1170) -- (21.4220,18.5620) --
    (41.4840,18.5620) -- (41.4840,21.3980) -- (13.4530,21.3980)
    .. controls (13.4530,21.3980) and (0.0000,19.8710)
    .. (0.0000,41.0860) .. controls (0.0000,62.3010) and
    (11.7420,61.5470) .. (11.7420,61.5470) -- (18.7500,61.5470) --
    (18.7500,51.7030) .. controls (18.7500,51.7030) and
    (18.3710,39.9610) ..  (30.3050,39.9610) .. controls
    (42.2380,39.9610) and (50.2030,39.9610) ..  (50.2030,39.9610)
    .. controls (50.2030,39.9610) and (61.3830,40.1410) ..
    (61.3830,29.1560) .. controls (61.3830,18.1720) and
    (61.3830,10.9920) ..  (61.3830,10.9920) .. controls
    (61.3830,10.9920) and (63.0820,0.0000) ..  (41.1090,0.0000) --
    cycle(30.0470,6.3520) .. controls (32.0430,6.3520) and
    (33.6560,7.9650) .. (33.6560,9.9610) .. controls (33.6560,11.9570)
    and (32.0430,13.5700) .. (30.0470,13.5700) .. controls
    (28.0510,13.5700) and (26.4380,11.9570) .. (26.4380,9.9610)
    .. controls (26.4380,7.9650) and (28.0510,6.3520)
    .. (30.0470,6.3520) -- cycle;
  \end{scope}

  \begin{scope}[shift={(81,-81)},xscale=-1]
    \fill[jaunpyth] (41.1090,0.0000) .. controls (20.0860,0.0000) and
    (21.3980,9.1170) ..  (21.3980,9.1170) -- (21.4220,18.5620) --
    (41.4840,18.5620) -- (41.4840,21.3980) -- (13.4530,21.3980)
    .. controls (13.4530,21.3980) and (0.0000,19.8710)
    .. (0.0000,41.0860) .. controls (0.0000,62.3010) and
    (11.7420,61.5470) .. (11.7420,61.5470) -- (18.7500,61.5470) --
    (18.7500,51.7030) .. controls (18.7500,51.7030) and
    (18.3710,39.9610) ..  (30.3050,39.9610) .. controls
    (42.2380,39.9610) and (50.2030,39.9610) ..  (50.2030,39.9610)
    .. controls (50.2030,39.9610) and (61.3830,40.1410) ..
    (61.3830,29.1560) .. controls (61.3830,18.1720) and
    (61.3830,10.9920) ..  (61.3830,10.9920) .. controls
    (61.3830,10.9920) and (63.0820,0.0000) ..  (41.1090,0.0000) --
    cycle(30.0470,6.3520) .. controls (32.0430,6.3520) and
    (33.6560,7.9650) .. (33.6560,9.9610) .. controls (33.6560,11.9570)
    and (32.0430,13.5700) .. (30.0470,13.5700) .. controls
    (28.0510,13.5700) and (26.4380,11.9570) .. (26.4380,9.9610)
    .. controls (26.4380,7.9650) and (28.0510,6.3520)
    .. (30.0470,6.3520) -- cycle;
  \end{scope}
\end{tikzpicture}} 

\ExplSyntaxOn
\NewPitonEnvironment{Python}{}
  { 
    \noindent \PythonLogo\newline \nobreak
    \leavevmode 
    \hspace* { 7.4 pt } 
    \vrule width 1pt 
    \hspace* { 5 pt } 
    \dim_set:Nn \l_tmpa_dim { \linewidth - 12.4 pt }
    \begin { minipage } { \l_tmpa_dim }
  }
  { \end { minipage } }
\ExplSyntaxOff

\begin{document}

\lipsum[1]

\begin{Python}
class PCFS(StratégieOrdonnancement):
    def elire(sef):
        p = min(selp.fp.data, key = lambda p : p.taP)
        if p.taP <= self.horlogie:
            p.changerEtat("Elu")
\end{Python}

\end{document}

The code for the logo of Python has been taken here.

Output of the above code

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.