2

I'd like to highlight some specific words for HTML5 code manually in LaTeX. In other words, I don't want to define an exact structure for highlighting the language, but do the highlights only for the words I select. So let's say for the code below, I only want to make signin-login bold and green, and only its type="text" bold and red, while the rest of the code stays the same.

    <form id="navbar-loginform" class="navbar-form navbar-right hidden">
    <div class="form-group">
    <input id="signin-login" highlight="" placeholder="Username" class="form-control" type="text">
    </div>
    <div class="form-group">
    <input id= "signin-password" highlight="" placeholder="Password" class="form-control" type="password">
    </div>
    <button highlight="" type="submit" class="btn btn-success">Sign in</button>
    </form>

How can I achieve this? Could you please show me a short working example for this?

  • 3
    Welcome to TeX.SX. Please provide some more information on how you are working. Add a minimal working example showing your documentclass, the packages you want to use herefore and the \begin{document}...\end{document}-Block. – LaRiFaRi Mar 26 '14 at 13:14
  • Maybe this link helps you: tex.stackexchange.com/questions/91259/… – raedma Mar 26 '14 at 13:15
  • otherwise the listings-package might do the trick – raedma Mar 26 '14 at 13:31
3

One possibility using the listings package; since apparently you only want to highlight some specific strings, you can escape to LaTeX and do the coloring there (in my example I used the bera package just to have a mono-spaced font allowing boldface)

\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{bera}% for boldfaced typewriter font

\lstset{
basicstyle=\ttfamily,
columns=fullflexible,
breaklines=true,
escapeinside={@|}{|@}
}

\begin{document}

\begin{lstlisting}
    <form id="navbar-loginform" class="navbar-form navbar-right hidden">
    <div class="form-group">
    <input id="@|\color{red}\bfseries signin-login|@" highlight="" placeholder="Username" class="form-control" @|\color{green!70!black}\bfseries type="text"|@>
    </div>
    <div class="form-group">
    <input id= "signin-password" highlight="" placeholder="Password" class="form-control" type="password">
    </div>
    <button highlight="" type="submit" class="btn btn-success">Sign in</button>
    </form>
\end{lstlisting}

\end{document}

enter image description here

Of course, the package offers you many features for highlighting keywords, comments, etc. Please refer to the package documentation.

  • It worked exactly in a way I hoped. It also works for manually defined colors, too. Thanks a lot. – telvin Mar 26 '14 at 15:37

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.