निरंजन
I want to make a command which saves the last character (at that point of document) in a macro which can be used later. Consider this MWE -
```
\documentclass[border=0.5cm]{standalone}
\usepackage{newunicodechar}
\newunicodechar{æ}{
% I want a command which will print the preceding character here.
}
\begin{document}
aæ
\end{document}
```
Considering my comment the output of this MWE should be `aa` and not `a`.
How to achieve this?
Top Answer
samcarter
Based on https://tex.stackexchange.com/questions/294118/how-can-i-define-my-own-ligatures-in-lualatex/294154#294154 you can play a bit with lua:
```
% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{fontspec}
\setmainfont{Arial}
%% Lua-side code
\usepackage{luacode}
\begin{luacode*}
function myligs ( s )
s = unicode.utf8.gsub ( s , '(\\?)([%a@]+)' , function( backslash, text )
-- no substitutions inside (La)TeX macros
if backslash=='' then
text = unicode.utf8.gsub(text, '(.)(æ)', '%1a' )
end
return backslash .. text
end)
return s
end
\end{luacode*}
\begin{document}
\directlua{luatexbase.add_to_callback("process_input_buffer", myligs, "myligs")}
am
aæ
bæ
ax
\end{document}
```

(depending on the possible values for a, b etc. another filter then `.` might be more appropriate)