1

I want to be able to present short code in the middle of a sentence. How can I highlight text in the middle of sentences in Latex so it they appear as code. Consider this example

For this purpose we use the optim() function.

I have highlighted "optim()". How can I do this exact thing in latex document?

moewe
  • 175,683
k.dkhk
  • 159
  • 4
    The listings package has \lstinline; minted has \mintinline. For very short stuff you could in theory also use \texttt as long as the code does not contain characters special for LaTeX. Do you also want the grey background or is it enough to change the font? – moewe Jan 29 '19 at 15:17
  • Those are good suggestions, thanks! It it possible to highlight though? Ideally I will make a line look exactly like the example. – k.dkhk Jan 29 '19 at 15:21
  • Maybe a duplicate of https://tex.stackexchange.com/questions/120966/highlight-verb-in-inline-text or https://tex.stackexchange.com/questions/436888/how-to-highlight-some-inline-text-using-parbox – James Jan 29 '19 at 15:27
  • 1
    Also related https://tex.stackexchange.com/q/357227/35864, https://tex.stackexchange.com/q/28179/35864, https://tex.stackexchange.com/q/94965/35864 – moewe Jan 29 '19 at 15:45
  • 1
    Please clarify what you mean by "highlight". E.g., a special font, a change in font size, a special foreground color, a special background color (and, if so, which color -- does it have to be grey?), or something else? – Mico Jan 29 '19 at 15:51

0 Answers0