TeX - LaTeX Asked by Niranjan on May 8, 2021
I recently came to know about the command DeclareUnicodeAccent
which can declare a diacritic which is printed after the argument of the declared command. e.g.
documentclass{article}
usepackage{fontspec}
setmainfont{CharisSIL}
DeclareUnicodeAccent{foo}{TU}{"031F} % ̟
begin{document}
foo{b}
end{document}
produces b̟
–
Now I want a similar command for conjoining diacritics. It should declare the command in such a way that the diacritic will be placed between the first and the second character of its argument. A dummy (not working) code is as follows.
documentclass{article}
usepackage{fontspec}
setmainfont{CharisSIL}
DeclareUnicodeConjoiningDiacritic{bar}{TU}{"0361} % ͡
begin{document}
bar{ab}
end{document}
Shall produce a͡b
–
In source2e.pdf
I found the following definition for DeclareUnicodeAccent
(which was quite easy to understand), but I didn’t understand the definition of add@unicode@accent
which must be renewed in order to produce the results correctly.
defadd@unicode@accent#1#2{%
ifrelaxdetokenize{#2}relax^^a0else#2fi
char#1relax}
defDeclareUnicodeAccent#1#2#3{%
DeclareTextCommand{#1}{#2}{add@unicode@accent{#3}}%
}
I want to understand what add@unicode@accent
exactly does and how to renew it for the command that I want to develop.
Here's an implementation:
documentclass{article}
usepackage{fontspec}
setmainfont{Doulos SIL}
NewDocumentCommand{conjoining}{m >{SplitArgument{1}{}}m}{%
makeconjoining{#1}#2%
}
NewDocumentCommand{makeconjoining}{mmm}{%
#2symbol{"#1}#3%
}
NewDocumentCommand{doubleinvertedbreve}{m}{%
conjoining{0361}{#1}%
}
begin{document}
doubleinvertedbreve{ab}
doubleinvertedbreve{AB}
doubleinvertedbreve{aB}
doubleinvertedbreve{Ax}
end{document}
What does DeclareUnicodeAccent
do?
defDeclareUnicodeAccent#1#2#3{%
DeclareTextCommand{#1}{#2}{add@unicode@accent{#3}}%
}
It is an interface to DeclareTextCommand
, so
DeclareUnicodeAccent{foo}{TU}{<number>}
is the same as
DeclareTextCommand{foo}{TU}{add@unicode@accent{<number>}}
Hence, if the current encoding is TU
, the command foo{x}
will do
add@unicode@accent{<number>}{x}
and the definition of add@unicode@accent
is very simple:
defadd@unicode@accent#1#2{%
ifrelaxdetokenize{#2}relax^^a0else#2fi
char#1relax}
which means that if the second argument is empty, the character U+00A0 is inserted, followed by char<number>relax
.
It simply isn't what you're looking for.
Correct answer by egreg on May 8, 2021
A small modification of the answer by egreg to lower the accent in case both letters are small (i.e., no ascenders). It works by measuring the height of the argument and calculating the difference between this height and the height of the combination AX.
documentclass{article}
usepackage{fontspec}
usepackage{calc}
setmainfont{DejaVu Serif}
newdimenconjh
newdimenupperh
NewDocumentCommand{conjoining}{m >{SplitArgument{1}{}}m}{%
makeconjoining{#1}#2%
}
NewDocumentCommand{makeconjoining}{mmm}{%
settoheight{upperh}{AX}%
settoheight{conjh}{#2#3}%
#2raisebox{conjh-upperh}{symbol{"#1}}#3%
}
NewDocumentCommand{doubleinvertedbreve}{m}{%
conjoining{0361}{#1}%
}
begin{document}
doubleinvertedbreve{ab}
doubleinvertedbreve{AB}
doubleinvertedbreve{aB}
doubleinvertedbreve{Ax}
doubleinvertedbreve{ax}
Huge
doubleinvertedbreve{ab}
doubleinvertedbreve{AB}
doubleinvertedbreve{aB}
doubleinvertedbreve{Ax}
doubleinvertedbreve{ax}
end{document}
Answered by Marijn on May 8, 2021
What you need to do at TeX primitive level looks like this:
defbar#1{barA#1}
defbarA#1#2{setbox0=hbox{#1#2}dimen0=ht0
ifdimdimen0>1ex advancedimen0 by-1ex else dimen0=0pt fi
#1raisedimen0hbox{char"0361}#2%
}
bar{aB}
Answered by wipet on May 8, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP