3

I'm employing the listings package to show VHDL code in my document in a nice way, to do so, I have defined my own version of VHDL, thus:

\documentclass{article}
\usepackage{listings}
\usepackage[usenames,dvipsnames]{xcolor}
\lstdefinelanguage{VHDL}{
  morekeywords=[1]{
    library,use,all,entity,is,port,in,out,end,architecture,of,
    begin,and,or,Not,downto,ALL
  },
  morekeywords=[2]{
    STD_LOGIC_VECTOR,STD_LOGIC,IEEE,STD_LOGIC_1164,
    NUMERIC_STD,STD_LOGIC_ARITH,STD_LOGIC_UNSIGNED,std_logic_vector,
    std_logic
  },
  morecomment=[l]{--}
}

\colorlet{keyword}{blue!100!black!80}
\colorlet{STD}{Lavender}
\colorlet{comment}{green!80!black!90}
\lstdefinestyle{VHDL}{
  language     = VHDL,
  basicstyle   = \footnotesize \ttfamily,
  keywordstyle = [1]\color{keyword}\bfseries,
  keywordstyle = [2]\color{STD}\bfseries,
  commentstyle = \color{comment}
  breaklines=true,                % sets automatic line breaking
  tabsize=3                                % sets default tabsize to 2 spaces
}

The output formatting is almost perfect but for the comments, where the program substitudes the white-spaces for the "breaklines" word. This code:

\begin{document}
\begin{lstlisting}[style=vhdl]

-- attribute s : string;
signal partial_from_static : std_logic_vector(3 downto 0) := (others => '1');
signal partial_to_static : std_logic_vector(3 downto 0) := (others => '1');
signal static_from_partial : std_logic_vector(3 downto 0) := (others => '1');

-- instantiation of instBusMacro
instBusMacro : BM_V5_L4_R4_single
Port Map (
    RH0 => '1',
\end{lstlisting}
\end{document}

Gives this output:

breaklines--breaklines breaklinesattributebreaklines breaklinessbreaklines breaklines:breaklines breaklinesstringbreaklines;

signal partial_from_static : std_logic_vector (3 downto 0) := ( others => '1 '); signal partial_to_static : std_logic_vector (3 downto 0) := ( others => '1 '); signal static_from_partial : std_logic_vector (3 downto 0) := ( others => '1 ');

breaklines--breaklines breaklinesinstantiationbreaklines breaklinesofbreaklines breaklinesinstBusMacro

instBusMacro : BM_V5_L4_R4_single Port Map ( RH0 => '1',

Both the comments and the keywords are correctly recognised, as their formatting has change accordantly, but those "breaklines" are driving me nuts.

What I have learned so far:

The listings package documentation says that the "other" type of characters (!,-,> and more) aren't allowed inside the comment definition, so I'm pretty sure here is the problem. It also says that in other part of the documentation is shown how to include them, but I only have been able to find how to use those characters as keywords, which I find useless for commenting.

Thank you all and sorry if I made some etiquette mistake, it's my first time posting here.

Edit:

I had forgotten to put a coma in:

  commentstyle = \color{comment}
  breaklines=true,

So trivial mistake, little to see here.

4
  • I think you are missing a comma just before "breaklines"
    – Thruston
    Commented Nov 20, 2013 at 14:17
  • commentstyle = \color{comment} should have a trailing comma?
    – Thruston
    Commented Nov 20, 2013 at 14:18
  • Holy ****. You are completely right. It's the coma before "breaklines". First time posting in these places and is something trivial. Way to go. Thank you very much.
    – user41358
    Commented Nov 20, 2013 at 14:21
  • Don't feel bad! You posted a complete working example and it was therefore really easy to answer.
    – Thruston
    Commented Nov 20, 2013 at 14:24

1 Answer 1

2
\lstdefinestyle{VHDL}{
  language     = VHDL,
  basicstyle   = \footnotesize \ttfamily,
  keywordstyle = [1]\color{keyword}\bfseries,
  keywordstyle = [2]\color{STD}\bfseries,
  commentstyle = \color{comment},%%%%%%%%%%
  breaklines=true,                % sets automatic line breaking
  tabsize=3                                % sets default tabsize to 2 spaces
}

your own definition read

commentstyle = \color{comment}breaklines=true,

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .