2

I followed some QA links like this in tex stackexchange and use this example tex code:

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\usepackage[algosection, boxruled, linesnumbered]{algorithm2e}

\SetProcNameSty{textbf} \SetProcArgSty{textbf} \SetProgSty{textbf}

\begin{document} \begin{procedure} \SetKwProg{Fn}{Function}{ is}{end} \Fn{afunc(i: int) : int}{return 0;} \caption{removemarked()} \label{alg:removemarked}

\end{procedure} \end{document}

I also viewed the official doc:

\SetKwProg{Prog}{Title}{ is}{end} Env is a block with ’Title’ (in CapSty style) at the beginning followed by args in ProgSty followed by ’is’ then ’text’ inside a block ended by ’end’.

In the output pdf, the procedure font has been modified to be bold by \SetProcNameSty{textbf} but the KwProg args afunc(i: int) : int haven't by changing ProgSty: enter image description here

One workaround:

Then I tried to directly format the arg text by using \bfseries, i.e. \Fn{\bfseries afunc(i: int) : int}{return 0\;}, it works as expected. enter image description here

Q: How to set the KwProg arg font style with something like \SetProgSty, e.g. by modifying the default italic with the textbf above?

An5Drama
  • 63
  • 6

1 Answers1

1

With \renewcommand{\SetProgSty}[1]{\renewcommand{\ProgSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}% added before \SetProgSty{textbf}, the problem is solved.


Maybe this question is too specific and is not one good question. Then I took some time to reinspect it when it has no replies for some time.

Inspired by this, I viewed the algorithm2e code (Sorry for not viewing it when posting. I should think of seeking for the code help when I have programmed for some long time) and found

\newcommand{\ProgSty}[1]{\textnormal{\emph{#1}}\unskip}%\SetProgSty{emphg} 
\newcommand{\SetProgSty}[1]{\renewcommand{\ArgSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
...
\newcommand{\SetKwProg}[4]{%\SetKwProg{Env}{Title}{is}{end} 
    \algocf@newcmdside@koif{#1}{\KwSty{#2}\ifArgumentEmpty{#2}\relax{\ }\ProgSty{##2}\KwSty{#3}\ifArgumentEmpty{##1}\relax{ ##1}\algocf@block{##3}{#4}{##4}}%

Since the \SetKwProg use \ProgSty but \SetProgSty doesn't change it as the code shows, so the original \SetProgSty doesn't work. Then I thought of the above solution.

Hope this can help the future readers.

An5Drama
  • 63
  • 6