Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

What is the simplest way to make coloured boxes with rounded corners in luatex? With xelatex I used pstricks and it was simple, but with luatex it is not working.

share|improve this question

1 Answer 1

up vote 10 down vote accepted

The simplest method is to use the mdframed or the tcolorbox package (example for tcolorbox: http://ctan.org/tex-archive/macros/latex/contrib/tcolorbox) package, which use TikZ. You can integrate with Lua as per the following MWE example, which uses both packages. It also runs the code and typesets the example. Please ensure you have the latest versions for all and run as LuaLaTeX (tcolorbox was updated recently).

enter image description here

I have used the same base code from another post of mine How can I produce vertical white space in a table with LuaLaTeX?, which I posted tonight. Have a look also at that post for unframed boxes (they look better to me).

\documentclass{book}
\usepackage[listings]{tcolorbox}
\lstloadlanguages{[LaTeX]TeX, [primitive]TeX,Pascal}
\usepackage{filecontents}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{amsmath}
\usepackage{luacode} % loads luatexbase as well
\newcommand\emphasis[2][blue]{\lstset{emph={exec,if,then,else,do,end,while,for,print,sprint,directlua,#2},
   emphstyle={\ttfamily\textcolor{#1}}}}%
\lstset{language={[LaTeX]TeX},
      stepnumber=1,numbersep=5pt, 
      numberstyle={\footnotesize\color{gray}},%firstnumber=last,
      breaklines=true,
      framesep=5pt,
      basicstyle=\small\ttfamily,
      showstringspaces=false,
      keywordstyle=\ttfamily\textcolor{blue},
      stringstyle=\color{orange},
      commentstyle=\color{black},
      rulecolor=\color{gray!10},
      breakatwhitespace=true,
      showspaces=false,  % shows spacing symbol
      backgroundcolor=\color{gray!15}}

\makeatother
\begin{document}

\emphasis{return,repeat,until,function,local}
\begin{tcblisting}{}
\begin{luacode}
-- example adapted from
-- http://rosettacode.org/wiki/Happy_numbers
function boxit(color, var, s)
 zz="\\mdframed[roundcorner=3pt, leftmargin=2cm,innertopmargin=0pt,innerbottommargin=0pt, innerleftmargin=0pt,innerrightmargin=0pt, innerlinewidth=0pt, middlelinewidth=0pt,outerlinewidth=1pt, outerlinecolor=red]"..var.."\\endmdframed"
 return zz
end
function digits(n)
  if n > 0 then return n \% 10, digits(math.floor(n/10)) end
end
function sumsq(a, ...)
  return a and a ^ 2 + sumsq(...) or 0
end
local happy = setmetatable({true, false, false, false}, {
      __index = function(self, n)
         self[n] = self[sumsq(digits(n))]
         return self[n]
      end } )
i, j = 0, 8
repeat
   i, j = happy[j] and (tex.sprint(boxit(violet, j, " ")) or i+1) or i, j + 1
until i == 17 --or j > 999
\end{luacode}
\end{tcblisting}
\end{document}
share|improve this answer
    
I would recommend tcolorbox. pstricks allows no page breaks so it's the nearest. –  Marco Daniel Mar 18 '12 at 18:42
    
@MarcoDaniel The post has both:) Can you help with the style to get it nearer to boxit in the link I posted in the answer? I am not very familiar with your package. –  Yiannis Lazarides Mar 18 '12 at 18:44
    
@YiannisLazarides: I compiled the tcolorbox example with lualatex and it just worked. –  Stephen Mar 18 '12 at 18:54
    
@Stephen -- Thanks for the test and the edit for the links. The tcblisting I used is one of the environments of tcolorbox. Great package. –  Yiannis Lazarides Mar 18 '12 at 18:59
    
tcolorbox is really nice, thank you very much! –  SadChi Mar 18 '12 at 19:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.