I have a problem about make a listing program and I want make it like this:


For my example:


But, I want to replace Example1 and Example2 with:

\lstinline+\documentclass[a4paper, 12pt]+

And Replace Example3 and Example4 with:

\lstinline+Pilihan Kelas+

How can I make it?

  • Where is the math in this? Otherwise, I would suggest the tcolorbox for quite nice listings. – user31729 Oct 6 '14 at 12:12
  • I think he means the braces above and below the code. – Astrinus Oct 6 '14 at 12:17
  • @Astrinus yes, you true how to make it ? – Hirwanto Oct 6 '14 at 12:19

If you must do this, it is possible with tikzmark. But watch out that you choose an appropriate escape character, which is never used in the listing itself.

I would not recommend it though. It requires manual edits to your listing source, which may or may not be feasible, depending on the length of the listing. There are also better, clearer ways to explain source code than this.


|\tikzmark{mark1begin}|\documentclass[<options>]|\tikzmark{mark1end}|{|\tikzmark{mark2begin}|<class name>|\tikzmark{mark2end}|}
\begin{tikzpicture}[overlay,remember picture]
    (pic cs:mark1begin) -- (pic cs:mark1end) node[midway,above] {[illegible]};
    (pic cs:mark2begin) -- (pic cs:mark2end) node[midway,below] {[illegible]};

enter image description here


This is an attempt, but I am not sure what the OP really requires.



\begin{tcblisting}{listing only,arc=0mm,auto outer arc}



enter image description here

  • I want make math mode and listing environments – Hirwanto Oct 6 '14 at 12:52
  • @Hirwanto: Could you explain what you really want to achieve? – user31729 Oct 6 '14 at 12:53
$\texttt{\textbackslash}\overbrace{\texttt{documentclass[<options>]}}^{\textrm{above text}}\underbrace{\texttt{\{<options<\}}}_{\textrm{below text}}$

Next time post a better quality image, please.

EDIT: after your edit, I think you can't mix math mode and listing environments... Mine is a workaround.

  • I hope, there are not more code lines than just the one posted in the image, otherwise it could be tedious to do this like you proposed ;-) – user31729 Oct 6 '14 at 12:30
  • @Astrinus, How to make it with listings package ? – Hirwanto Oct 6 '14 at 12:30
  • As said in the edited answer, I don't know. Math mode and listing environments are treated very different by TeX. – Astrinus Oct 6 '14 at 12:32
  • @Astrinus, Yeah, i want to make math mode and listing environments, – Hirwanto Oct 6 '14 at 12:34
  • @Hirwanto what I'm saying is that I think there's no way to make them work together. – Astrinus Oct 6 '14 at 12:38

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.