Search code examples
latexmarkdownoverleaf

How to highlight an inline code snippet in latex?


I would like to hightlight a piece of code in the middle of a body of text. I would like it to appear similar to the inline heightlight in markdown.

I want it to look like this: tensorflow.keras.optimizers


Solution

  • You can use the listing and tcolorbox packages:

    \documentclass{article}
    
    \usepackage{xspace}
    \usepackage{tcolorbox}
    \tcbuselibrary{listings}
    
    \newtcblisting{foo}{
      listing only,
      nobeforeafter,
      after={\xspace},
      hbox,
      tcbox raise base,
      fontupper=\ttfamily,
      colback=lightgray,
      colframe=lightgray,
      size=fbox
      }
    
    \begin{document}
    
    text
    \begin{foo}
    code
    \end{foo}
    text
    
    
    \end{document}
    

    enter image description here