add tag
निरंजन
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}
```

![Screen Shot 2020-09-18 at 21.37.50.png](/image?hash=5a19e0c555a345cd55a775d0e0dfdbc3c841b1beae99dcc46fb66dae484eac2d)

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

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.