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.

How to add a few blank lines without using \vspace? Trying to use \\ always gets me in trouble...

Now I'm trying to format a simple lua table in LaTeX for display. I am using a combination of \\ (which requires me to use code like \noexpand\\noexpand\\) and \vspace.

The table is formated nicely EXCEPT I have to use an actual character

tex.print("-")

works fine but if I change it to

tex.print("\noexpand~")

or

tex.print(" ")

things quickly become bad.

I've also tried

tex.print("\noexpand\\hspace\noexpand{1mm\noexpand}")

but it only works if there is some initial piece of text

My Code

for i = 0, ofs + 1*idx - 1 do
    tex.print("-")
    tex.print("\noexpand\\hspace\noexpand{0.1mm\noexpand}")                            
end
share|improve this question
3  
The correct method for inserting vertical space is \vspace when in normal text; in a tabular environment it is \\[<dimen>]. Please edit your message, removing foul language. –  egreg Mar 18 '12 at 14:18
    
If you start a new line with \hspace it doesn't work. You have to use the stared form of the command: \hspace*{...}. –  Holle Mar 18 '12 at 14:30
    
ok, that would then be the cause. –  Uiy Mar 18 '12 at 14:32
3  
Please use a decent language in your posts. I edited your question. –  Stefan Kottwitz Mar 18 '12 at 14:48
2  
I repeat my question: Do you need the word crap here? We don't own this place but we have reached to an equilibrium where now there is a certain reputation about the level of noise here. I think we achieved it by not trying to offend anyone. Your words are like a bird chirp to me if I consider my own daily foul language and I repeat that I am not offended. But we don't need to carry it over here. Because it is a Q&A site with heavy google traffic from everywhere. It is not a forum where we exchange ideas or opinions. Just take your time and look at the questions' brevity in general. –  percusse Mar 18 '12 at 15:12
show 6 more comments

1 Answer

up vote 1 down vote accepted

You need to decide if you coding in TeX or you still thinking in another computer language. I can gather from your comments such as "...drives me nuts", "...things go to hell in a handbasket real quick" that you have a hard time adapting. So I would suggest rather think in "Lua", move all your coding into the Lua part.

Here is an example that justs does and calculates happy numbers that might also make you a bit happier:)

All the typesetting has been moved onto a function in this case \boxit thus having a good separation of concerns; think the same way for your table, post a minimal and maybe the community can take it up from there.

\documentclass{tufte-book}
\usepackage[listings]{tcolorbox}
\lstloadlanguages{[LaTeX]TeX, [primitive]TeX,Pascal}
\usepackage{filecontents}
\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},
      escapeinside={{(*@}{@*)}}, 
       gobble=0,
       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}}
\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)
  return "\\fbox{\\strut\\color{violet} "..var.."} "
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 also can't use luacode as I get errors. If I change luadirect to luaexec it fails to work even on an empty block. I've moved many functions I use to an external lua file but I like to work in one file as I don't have to switch back and forth(which is better for learning as it is more efficient(or should be)) –  Uiy Mar 18 '12 at 14:56
    
@Uiy Hang in there! Leave your package aside for a day or two and put effort to work out a few long examples in (La)TeX. Read something that has a beginning and an end and then tackle the package again. Or go for all Lua as shown in my post. That way you contain the problems and you can handle them later rather than stop the programming flow. –  Yiannis Lazarides Mar 18 '12 at 15:01
    
@Uiy I use a basic file as above to test (it is all in one file) and the output is at the bottom of the box, nicely typeset. When it works I move it onto the main files. –  Yiannis Lazarides Mar 18 '12 at 15:02
    
Thats what I do ;) But the problem is I have to escape everything in the tex file and then remove the escapes when I copy it over to the lua file. Luckily I don't have much more left to do... I hope. Lualatex is pretty cool but I don't have any idea why luacode is broke for me ;/ I'll make a post about it. –  Uiy Mar 18 '12 at 15:06
    
@Uiy I agree! rather make a post with a full MWE that shows the problem. Also read through \usepackage{luacode}. –  Yiannis Lazarides Mar 18 '12 at 15:20
show 2 more comments

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.