13.11.2015 Views

my Latex and Tex4ht cheat sheet

my Latex cheat sheet - 12000.org

my Latex cheat sheet - 12000.org

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2.43.4 reversing enumeration list<br />

Given enumeration list, where each item just uses one line, to reverse it:<br />

% !TEX TS-program = lualatex<br />

\documentclass{article}<br />

\usepackage{luacode}<br />

\usepackage{amsmath}<br />

%------------------------<br />

\begin{luacode*} -- copy the list here as is.<br />

data=[[\item 2001<br />

\item 2002<br />

\item 2003<br />

\item 2005 was a very good year<br />

\item 2006 was also a very good year<br />

\item 2007<br />

]]<br />

function string:split(sep) --http://lua-users.org/wiki/SplitJoin<br />

local sep, fields = sep or ":", {}<br />

local pattern = string.format("([^%s]+)", sep)<br />

self:gsub(pattern, function(c) fields[#fields+1] = c end)<br />

return fields<br />

end<br />

function flip()<br />

lines = data:split("\n")<br />

tex.print("\\begin{enumerate}")<br />

for i=#lines,1,-1 do<br />

tex.print(lines[i])<br />

end<br />

tex.print("\\end{enumerate}")<br />

end<br />

\end{luacode*}<br />

\newcomm<strong>and</strong>\flip[0]{ \directlua{flip()}}%<br />

\begin{document}<br />

\flip{}<br />

\end{document}<br />

Another way is<br />

47

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!