7

I would like to use a luadraw picture as a background image on a page. I tried overlay, but this is not working as the picture is shifted above right.

Luadraw is not (yet?) on CTAN, but available on github: luadraw

%!TEX TS-program = lualatex
\documentclass[a4paper]{article}
%\usepackage[ignoreall, margin=-0cm, marginparsep=0cm]{geometry}
\usepackage{luadraw}
\begin{document}
\begin{luadraw}{}
local g = graph:new{
    margins={0,0,0,0}
    , size={31,31}
    , pictureoptions="overlay"
    }
for j= 1, 5 do
    for k=1,10*j do
        g:Dcircle(Zp(j,k*math.pi/(5*j)),1)
    end
end
g:Show(true)
\end{luadraw}
% without overlay, the center of the picture (on a new page) is approximately at (20,10) (if (0,0) is the bottom left corner
% with overlay, the center of the picture is out the page (at (30,50) ? maybe)
\end{document}

(The original picture is more complex than this one, so using a standard tikzpicture is not really an option)

1 Answer 1

8

Here is a proposal:

% Source - https://tex.stackexchange.com/q/761440
% Posted by PHL, modified by community. See post 'Timeline' for change history
% Retrieved 2026-03-31, License - CC BY-SA 4.0

%!TEX TS-program = lualatex
\documentclass[a4paper]{article}
%\usepackage[ignoreall, margin=-0cm, marginparsep=0cm]{geometry}
\usepackage{luadraw}
\usepackage{eso-pic}
\usepackage{lipsum}

\begin{luacode*}
local g = graph:new{
    margins={0,0,0,0}
    , size={18,18} 
    }
g:Linecolor("lightgray")
for j= 1, 5 do
    for k=1,10*j do
        g:Dcircle(Zp(j,k*math.pi/(5*j)),1)
    end
end
g:Savetofile("mybackground.tkz")
\end{luacode*}

\AddToShipoutPictureBG{%
\AtPageCenter{%
        \put(-9cm,-9cm){\input{mybackground.tkz}}% 9cm = half width and half height of the picture
    }}
\begin{document}

\lipsum[1-2]
\newpage
\lipsum[1-2]

\end{document}

enter image description here

EDIT Here is a second version that takes into account samcarter's comment. Furthermore, in this second version, the background is redrawn on each page and can therefore be modified (in the first version the background was static).

% Source - https://tex.stackexchange.com/q/761440
% Posted by PHL, modified by community. See post 'Timeline' for change history
% Retrieved 2026-03-31, License - CC BY-SA 4.0

%!TEX TS-program = lualatex
\documentclass[a4paper]{article}
%\usepackage[ignoreall, margin=-0cm, marginparsep=0cm]{geometry}
\usepackage{luadraw}
\usepackage{lipsum}

\begin{luacode*}
function background()
    local g = graph:new{
        margins={0,0,0,0}
        , size={18,18} 
        }
    g:Linecolor("lightgray")
    for j= 1, 5 do
        for k=1,10*j do
            g:Dcircle(Zp(j,k*math.pi/(5*j)),1)
        end
    end
    g:Sendtotex()
end
\end{luacode*}
\def\background{\directlua{background()}}%

\AddToHook{shipout/background}
{%
    \put(\paperwidth/2-9cm,-\paperheight/2-9cm){\background}%
}    

\begin{document}

\lipsum[1-2]
\newpage
\lipsum[1-2]

\end{document}

The result is the same.

3
  • 3
    As an alternative without extra packages you could use the shipout/background hook, see tex.stackexchange.com/a/642026/36296 for an example Commented 18 hours ago
  • I did not think of using a hook to the shipout routine. But I do not complain, this work perfectly well Commented 18 hours ago
  • 1
    I have edited my answer with a second proposal. Commented 18 hours ago

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.