0

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

Tes

For my example:

\documentclass{article}
\usepackage{listing}
\usepackage{amsmath}
\begin{document}
$\underbrace{Example1}_{Example2}$\\
\\
$\overbrace{EXample}^{Example}$
\end{document}

But, I want to replace Example1 and Example2 with:

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

And Replace Example3 and Example4 with:

\lstinline+\documentclass{article}+
\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
4

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.

\documentclass{article}
\usepackage{listings,tikz}
\usetikzlibrary{decorations.pathreplacing,tikzmark}
\usetikzmarklibrary{listings}
\lstset{basicstyle=\ttfamily}

\begin{document}
\begin{lstlisting}[language={[LaTeX]TeX},escapechar=|]
|\tikzmark{mark1begin}|\documentclass[<options>]|\tikzmark{mark1end}|{|\tikzmark{mark2begin}|<class name>|\tikzmark{mark2end}|}
\end{lstlisting}
\begin{tikzpicture}[overlay,remember picture]
  \draw[overlay,decorate,decoration={brace},yshift=2ex] 
    (pic cs:mark1begin) -- (pic cs:mark1end) node[midway,above] {[illegible]};
  \draw[overlay,decorate,decoration={brace,mirror},yshift=-0.3em] 
    (pic cs:mark2begin) -- (pic cs:mark2end) node[midway,below] {[illegible]};
\end{tikzpicture}
\end{document}

enter image description here

2

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

\documentclass{article}


\usepackage{tcolorbox}
\tcbuselibrary{listings}

\begin{document}
\begin{tcblisting}{listing only,arc=0mm,auto outer arc}
\documentclass[<options>]{<documentclassname>}

\begin{document}
\tableofcontents
\chapter{section}

\end{document}
\end{tcblisting}
\end{document}

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
0
$\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.