Note: library is an advanced concept that most users don't have to consider.
Here is the structure of a library:
[#package packageName] ([#import importName])* ([#using usingName])* [#library visibility libraryName] ([#macro macroName(macroParameters)] (body statement)* [/#macro])* [/#library]
A text template can use libraries and can define local macros.
Here is the complete structure of a text template:
[#package packageName] ([#import importName])* ([#using usingName])* [#template visibility templateName(templateParameters)] (body statement)* [/#template] ([#macro macroName(macroParameters)] (body statement)* [/#macro])*