2

Something strange with algorithm2e comment. I'd like to make the left marker of the comment be a long dash. Similar to \textemdash. I was following the answer given here how-to-have-the-algorithmicx-comment-symbol-in-algorithm2e but instead of using a triangle marker as in the above link, I wanted instead to use ---. But I can't get it to work. (Actually the example in the answer above, does not compile for me on TL 2016).

Mathematica graphics

When I try \SetKwComment{comment}{\textemdash}{}, I do not get what I expected. I get something else. MWE

\documentclass{article}
\usepackage[linesnumbered]{algorithm2e}

%now set comment left marker
\SetKwComment{comment}{\textemdash}{}
\begin{document}

This \textemdash\ is a test.

\begin{algorithm}[H]
  \DontPrintSemicolon
  \SetAlgoLined
  \eIf{true}
  {
     $x=1$ \comment*{Some comment}
  }
  {
     $x=0$
  }
\end{algorithm}
\end{document}

Now

lualatex foo2.tex
This is LuaTeX, Version 0.95.0 (TeX Live 2016) 
 restricted system commands enabled.
(./foo2.tex
LaTeX2e <2016/03/31> patch level 2
Babel <3.9r> and hyphenation patterns for 1 language(s) loaded.
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2016/texmf-dist/tex/latex/algorithm2e/algorithm2e.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/ifthen.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/tools/xspace.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/relsize/relsize.sty)
********************************************************
Package `algorithm2e' Release 5.1 -- october 19 2015 --
- algorithm2e-announce@lirmm.fr mailing list for announcement about releases
- algorithm2e-discussion@lirmm.fr mailing list for discussion about package
subscribe by emailing sympa@lirmm.fr with 'subscribe <list> <firstname name>'
- Author: Christophe Fiorio (christophe.fiorio@umontpellier.fr)
********************************************************
) (./foo2.aux) [1{/usr/local/texlive/2016/texmf-var/fonts/map/pdftex/updmap/pdf
tex.map}] (./foo2.aux))
(\end occurred inside a group at level 1)

### simple group (level 1) entered at line 1061 ({)
### bottom level
 631 words of node memory still in use:
   3 hlist, 1 vlist, 2 rule, 31 glue, 59 glue_spec, 1 write nodes
   avail lists: 2:21,3:10,4:4,5:26,6:61,7:71,8:14,9:47,10:3
</usr/local/texlive/2016/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx10.pfb><
/usr/local/texlive/2016/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx7.pfb></u
sr/local/texlive/2016/texmf-dist/fonts/type1/public/amsfonts/cm/cmmi10.pfb></us
r/local/texlive/2016/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb></usr/
local/texlive/2016/texmf-dist/fonts/type1/public/amsfonts/cm/cmti10.pfb></usr/l
ocal/texlive/2016/texmf-dist/fonts/type1/public/amsfonts/cm/cmtt10.pfb>
Output written on foo2.pdf (1 page, 54390 bytes).
Transcript written on foo2.log.

gives

Mathematica graphics

I am doing something wrong. How to obtain --- for left comment marker? If I just write \SetKwComment{comment}{---}{} I get this:

Mathematica graphics

And they are not the same. I want the dash that looks solid, like on the first line above.

TL 2016

  • Try adding \usepackage[T1]{fontenc} – daleif Aug 23 '16 at 11:53
  • @daleif I did, it helped a little, but it is still not the long dash. I get very small dash. Actually, for lualatex, which is what I use, I was told \usepackage[T1]{fontenc} is not needed any more. So I do not include it. – Nasser Aug 23 '16 at 11:58
  • Then you might want to make it a lot more clear that you are using LuaLaTeX. I tend to stay away from it because of these problems/inconsistencies. I cannot help you further. BTW: have you tried \textnormal{\textemdash}? It seems from your image that the comment is in typewriter and an em-dash might not even exist in that font. – daleif Aug 23 '16 at 13:01
  • @daleif thanks, \textnormal{\textemdash} worked! if you like to post this as answer will accept it. sorry I was not clear about lualatex, but I showed the command I used which is lualatex. – Nasser Aug 23 '16 at 13:27
  • You should at least tag it as a lualatex question – daleif Aug 23 '16 at 13:55
2

I main issue might be that the monospace font(the comment seems to be typeset in a monospace font) does not have an emdash.

A simple remedy might be to use the one from the document font instead i.e. \textnormal{\textemdash} or something similar.

| improve this answer | |

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.