Lettrine + string manipulation + some fonts = errors and weird issuesLettrine package and the letter...
Why did UK NHS pay for homeopathic treatments?
What can a pilot do if an air traffic controller is incapacitated?
Does "as soon as" imply simultaneity?
Why are there two fundamental laws of logic?
A food item only made possible by time-freezing storage?
A high quality contribution but an annoying error is present in my published article
Is there any iPhone SE out there with 3D Touch?
Safely hang a mirror that does not have hooks
What benefits does the Power Word Kill spell have?
How do I deal with too many NPCs in my campaign?
Is "ln" (natural log) and "log" the same thing if used in this answer?
Does Sitecore have support for Sitecore products in containers?
Safe to use 220V electric clothes dryer when building has been bridged down to 110V?
Hiking with a mule or two?
Are lawyers allowed to come to agreements with opposing lawyers without the client's knowledge or consent?
Designing a time thief proof safe
How to deal with my team leader who keeps calling me about project updates even though I am on leave for personal reasons?
Organisational search option
Why is (inf + 0j)*1 == inf + nanj?
What is the need of methods like GET and POST in the HTTP protocol?
Going to France with limited French for a day
Is it really necessary to have a four hour meeting in Sprint planning?
Strange Sticky Substance on Digital Camera
What do you do if you have developments on your paper during the long peer review process?
Lettrine + string manipulation + some fonts = errors and weird issues
Lettrine package and the letter LLettrine and section at bottom of page causes bad pagebreakLettrine, accentuated characters and htlatexLettrine and WrapfigLettrine and Arabic scriptCapital letters and lettrineIssue: string manipulation with links insideConflict between lettrine and justifyHow to use lettrine with diacritics and makebox?midsloppy and lettrine do not play nice
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I am encountering some weird behavior and errors when manipulating strings inside of lettrine arguments: the code either doesn't compile or produces unexpected results. On top of that, it is font-related, e.g., some things work with regular fonts, but fail with some other fonts, such as most of fonts here: https://tug.org/FontCatalogue/otherfonts.html#initials
Any insight into this issue and advice on how one could fix this would be highly appreciated!
Here is a typical example:
documentclass{article}
usepackage{times,lettrine,Eileen,coolstr,stringstrings,xstring}
%renewcommand*{LettrineFontHook}{Eileenfamily} %%% Eileen fancy drop letter WTF?
newcommand*{first}[1]{substring{#1}{1}{1}} %%% stringstrings version
%newcommand*{first}[1]{substr{#1}{1}{1}} %%% coolstr version DOES NOT WORK AT ALL
%newcommand*{first}[1]{StrLeft{#1}{1}} %%% xstring version DOES NOT WORK AT ALL
begin{document}
lettrine{first{Whaaat}}{hat} the duck? %%% DOES NOT WORK AS INTENDED WITH EILEEN
vspace{3em}
lettrine{first{What}}{hat} the duck? %%% DOES NOT WORK AT ALL WITH EILEEN
end{document}
lettrine stringstrings
New contributor
add a comment
|
I am encountering some weird behavior and errors when manipulating strings inside of lettrine arguments: the code either doesn't compile or produces unexpected results. On top of that, it is font-related, e.g., some things work with regular fonts, but fail with some other fonts, such as most of fonts here: https://tug.org/FontCatalogue/otherfonts.html#initials
Any insight into this issue and advice on how one could fix this would be highly appreciated!
Here is a typical example:
documentclass{article}
usepackage{times,lettrine,Eileen,coolstr,stringstrings,xstring}
%renewcommand*{LettrineFontHook}{Eileenfamily} %%% Eileen fancy drop letter WTF?
newcommand*{first}[1]{substring{#1}{1}{1}} %%% stringstrings version
%newcommand*{first}[1]{substr{#1}{1}{1}} %%% coolstr version DOES NOT WORK AT ALL
%newcommand*{first}[1]{StrLeft{#1}{1}} %%% xstring version DOES NOT WORK AT ALL
begin{document}
lettrine{first{Whaaat}}{hat} the duck? %%% DOES NOT WORK AS INTENDED WITH EILEEN
vspace{3em}
lettrine{first{What}}{hat} the duck? %%% DOES NOT WORK AT ALL WITH EILEEN
end{document}
lettrine stringstrings
New contributor
1
I understand your goals and they are noble. However, when I wanted to uselettrine
(and had no time), I just definednewcommand{flx}[2]{lettrine[lines=4,realheight=true]{#1}{textsc{#2}}}
and did the separation in first letter and remaning part myself. You uselettrine
once per chapter, it's not that much work.
– Oleg Lobachev
7 hours ago
1
Oleg: thanks for responding, however, this would not work for me, as the presented piece of code is just for illustration purposes. My actual code does the parsing automatically and has to extract first letters from words on its own. I've accepted Steven B. Segletes' answer, as not only it fixes the problem, but also teaches some TeX programming :) Thank you, Steven!
– Iiro Ullin
7 hours ago
add a comment
|
I am encountering some weird behavior and errors when manipulating strings inside of lettrine arguments: the code either doesn't compile or produces unexpected results. On top of that, it is font-related, e.g., some things work with regular fonts, but fail with some other fonts, such as most of fonts here: https://tug.org/FontCatalogue/otherfonts.html#initials
Any insight into this issue and advice on how one could fix this would be highly appreciated!
Here is a typical example:
documentclass{article}
usepackage{times,lettrine,Eileen,coolstr,stringstrings,xstring}
%renewcommand*{LettrineFontHook}{Eileenfamily} %%% Eileen fancy drop letter WTF?
newcommand*{first}[1]{substring{#1}{1}{1}} %%% stringstrings version
%newcommand*{first}[1]{substr{#1}{1}{1}} %%% coolstr version DOES NOT WORK AT ALL
%newcommand*{first}[1]{StrLeft{#1}{1}} %%% xstring version DOES NOT WORK AT ALL
begin{document}
lettrine{first{Whaaat}}{hat} the duck? %%% DOES NOT WORK AS INTENDED WITH EILEEN
vspace{3em}
lettrine{first{What}}{hat} the duck? %%% DOES NOT WORK AT ALL WITH EILEEN
end{document}
lettrine stringstrings
New contributor
I am encountering some weird behavior and errors when manipulating strings inside of lettrine arguments: the code either doesn't compile or produces unexpected results. On top of that, it is font-related, e.g., some things work with regular fonts, but fail with some other fonts, such as most of fonts here: https://tug.org/FontCatalogue/otherfonts.html#initials
Any insight into this issue and advice on how one could fix this would be highly appreciated!
Here is a typical example:
documentclass{article}
usepackage{times,lettrine,Eileen,coolstr,stringstrings,xstring}
%renewcommand*{LettrineFontHook}{Eileenfamily} %%% Eileen fancy drop letter WTF?
newcommand*{first}[1]{substring{#1}{1}{1}} %%% stringstrings version
%newcommand*{first}[1]{substr{#1}{1}{1}} %%% coolstr version DOES NOT WORK AT ALL
%newcommand*{first}[1]{StrLeft{#1}{1}} %%% xstring version DOES NOT WORK AT ALL
begin{document}
lettrine{first{Whaaat}}{hat} the duck? %%% DOES NOT WORK AS INTENDED WITH EILEEN
vspace{3em}
lettrine{first{What}}{hat} the duck? %%% DOES NOT WORK AT ALL WITH EILEEN
end{document}
lettrine stringstrings
lettrine stringstrings
New contributor
New contributor
New contributor
asked 8 hours ago
Iiro UllinIiro Ullin
183 bronze badges
183 bronze badges
New contributor
New contributor
1
I understand your goals and they are noble. However, when I wanted to uselettrine
(and had no time), I just definednewcommand{flx}[2]{lettrine[lines=4,realheight=true]{#1}{textsc{#2}}}
and did the separation in first letter and remaning part myself. You uselettrine
once per chapter, it's not that much work.
– Oleg Lobachev
7 hours ago
1
Oleg: thanks for responding, however, this would not work for me, as the presented piece of code is just for illustration purposes. My actual code does the parsing automatically and has to extract first letters from words on its own. I've accepted Steven B. Segletes' answer, as not only it fixes the problem, but also teaches some TeX programming :) Thank you, Steven!
– Iiro Ullin
7 hours ago
add a comment
|
1
I understand your goals and they are noble. However, when I wanted to uselettrine
(and had no time), I just definednewcommand{flx}[2]{lettrine[lines=4,realheight=true]{#1}{textsc{#2}}}
and did the separation in first letter and remaning part myself. You uselettrine
once per chapter, it's not that much work.
– Oleg Lobachev
7 hours ago
1
Oleg: thanks for responding, however, this would not work for me, as the presented piece of code is just for illustration purposes. My actual code does the parsing automatically and has to extract first letters from words on its own. I've accepted Steven B. Segletes' answer, as not only it fixes the problem, but also teaches some TeX programming :) Thank you, Steven!
– Iiro Ullin
7 hours ago
1
1
I understand your goals and they are noble. However, when I wanted to use
lettrine
(and had no time), I just defined newcommand{flx}[2]{lettrine[lines=4,realheight=true]{#1}{textsc{#2}}}
and did the separation in first letter and remaning part myself. You use lettrine
once per chapter, it's not that much work.– Oleg Lobachev
7 hours ago
I understand your goals and they are noble. However, when I wanted to use
lettrine
(and had no time), I just defined newcommand{flx}[2]{lettrine[lines=4,realheight=true]{#1}{textsc{#2}}}
and did the separation in first letter and remaning part myself. You use lettrine
once per chapter, it's not that much work.– Oleg Lobachev
7 hours ago
1
1
Oleg: thanks for responding, however, this would not work for me, as the presented piece of code is just for illustration purposes. My actual code does the parsing automatically and has to extract first letters from words on its own. I've accepted Steven B. Segletes' answer, as not only it fixes the problem, but also teaches some TeX programming :) Thank you, Steven!
– Iiro Ullin
7 hours ago
Oleg: thanks for responding, however, this would not work for me, as the presented piece of code is just for illustration purposes. My actual code does the parsing automatically and has to extract first letters from words on its own. I've accepted Steven B. Segletes' answer, as not only it fixes the problem, but also teaches some TeX programming :) Thank you, Steven!
– Iiro Ullin
7 hours ago
add a comment
|
2 Answers
2
active
oldest
votes
I recommend, in a case like this, doing it with raw TeX, without parsing packages.
documentclass{article}
usepackage{times,lettrine,Eileen}
deffirstaux#1#2relax{{#1}{#2}}
newcommandflettrine[1]{expandafterlettrinefirstaux#1relax}
begin{document}
flettrine{What} the duck?bigskip
renewcommand*{LettrineFontHook}{Eileenfamily}
flettrine{What} the duck?
end{document}
If you wanted to use stringstrings
for other reasons (more complex manipulations, for example), I would use substring
to store the result in thestring
, and then pass thestring
on to lettrine
, in this fashion:
documentclass{article}
usepackage{times,lettrine,Eileen,coolstr,stringstrings,xstring}
newcommand*{first}[1]{substring[q]{#1}{1}{1}} %%% stringstrings version
newcommandflettrine[2]{first{#1}lettrine{thestring}{#2}}
begin{document}
flettrine{Whaaat}{hat} the duck? %%% DOES NOT WORK AS INTENDED WITH EILEEN
vspace{3em}
renewcommand*{LettrineFontHook}{Eileenfamily} %%% Eileen fancy drop letter WTF?
flettrine{What}{hat} the duck? %%% DOES NOT WORK AT ALL WITH EILEEN
end{document}
add a comment
|
With expl3
it's really easy:
documentclass{article}
usepackage{newtxtext,lettrine,Eileen,xparse}
renewcommand*{LettrineFontHook}{Eileenfamily} %%% Eileen fancy drop letter WTF?
ExplSyntaxOn
NewDocumentCommand{IiroLettrine}{O{}m}
{
lettrine[#1]{tl_range:nnn { #2 } { 1 } { 1 }}{tl_range:nnn { #2 } { 2 } { -1 } }
}
ExplSyntaxOff
begin{document}
IiroLettrine{What} the duck?
end{document}
The problem with your code is that StrLeft{#1}{1}
doesn't produce the first letter, but the set of instructions for printing it, but lettrine
wants just a letter (after expansion).
The tl_range:nnn
function is fully expandable, so it makes no problem to lettrine
. With tl_range:nnn { #1 } { 1 } { 1 }
the first item in the argument is delivered; with tl_range:nnn { #1 } { 2 } { -1 }
the remaining items are produced (the negative second number means “up to the last item”).
Since small caps are needed, it's better to use newtxtext
that provides real small caps, instead of the faked ones you get with times
.
You can do it also with xstring
, using its trailing optional argument feature:
documentclass{article}
usepackage{newtxtext,lettrine,Eileen,xstring}
renewcommand*{LettrineFontHook}{Eileenfamily} %%% Eileen fancy drop letter WTF?
newcommand{IiroLettrine}[2][]{%
StrLeft{#2}{1}[firstletter]%
StrGobbleLeft{#2}{1}[otherletters]%
lettrine[#1]{firstletter}{otherletters}%
}
begin{document}
IiroLettrine{What} the duck?
end{document}
In both cases I kept the optional argument to lettrine
available in IiroLettrine
.
add a comment
|
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Iiro Ullin is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f509105%2flettrine-string-manipulation-some-fonts-errors-and-weird-issues%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I recommend, in a case like this, doing it with raw TeX, without parsing packages.
documentclass{article}
usepackage{times,lettrine,Eileen}
deffirstaux#1#2relax{{#1}{#2}}
newcommandflettrine[1]{expandafterlettrinefirstaux#1relax}
begin{document}
flettrine{What} the duck?bigskip
renewcommand*{LettrineFontHook}{Eileenfamily}
flettrine{What} the duck?
end{document}
If you wanted to use stringstrings
for other reasons (more complex manipulations, for example), I would use substring
to store the result in thestring
, and then pass thestring
on to lettrine
, in this fashion:
documentclass{article}
usepackage{times,lettrine,Eileen,coolstr,stringstrings,xstring}
newcommand*{first}[1]{substring[q]{#1}{1}{1}} %%% stringstrings version
newcommandflettrine[2]{first{#1}lettrine{thestring}{#2}}
begin{document}
flettrine{Whaaat}{hat} the duck? %%% DOES NOT WORK AS INTENDED WITH EILEEN
vspace{3em}
renewcommand*{LettrineFontHook}{Eileenfamily} %%% Eileen fancy drop letter WTF?
flettrine{What}{hat} the duck? %%% DOES NOT WORK AT ALL WITH EILEEN
end{document}
add a comment
|
I recommend, in a case like this, doing it with raw TeX, without parsing packages.
documentclass{article}
usepackage{times,lettrine,Eileen}
deffirstaux#1#2relax{{#1}{#2}}
newcommandflettrine[1]{expandafterlettrinefirstaux#1relax}
begin{document}
flettrine{What} the duck?bigskip
renewcommand*{LettrineFontHook}{Eileenfamily}
flettrine{What} the duck?
end{document}
If you wanted to use stringstrings
for other reasons (more complex manipulations, for example), I would use substring
to store the result in thestring
, and then pass thestring
on to lettrine
, in this fashion:
documentclass{article}
usepackage{times,lettrine,Eileen,coolstr,stringstrings,xstring}
newcommand*{first}[1]{substring[q]{#1}{1}{1}} %%% stringstrings version
newcommandflettrine[2]{first{#1}lettrine{thestring}{#2}}
begin{document}
flettrine{Whaaat}{hat} the duck? %%% DOES NOT WORK AS INTENDED WITH EILEEN
vspace{3em}
renewcommand*{LettrineFontHook}{Eileenfamily} %%% Eileen fancy drop letter WTF?
flettrine{What}{hat} the duck? %%% DOES NOT WORK AT ALL WITH EILEEN
end{document}
add a comment
|
I recommend, in a case like this, doing it with raw TeX, without parsing packages.
documentclass{article}
usepackage{times,lettrine,Eileen}
deffirstaux#1#2relax{{#1}{#2}}
newcommandflettrine[1]{expandafterlettrinefirstaux#1relax}
begin{document}
flettrine{What} the duck?bigskip
renewcommand*{LettrineFontHook}{Eileenfamily}
flettrine{What} the duck?
end{document}
If you wanted to use stringstrings
for other reasons (more complex manipulations, for example), I would use substring
to store the result in thestring
, and then pass thestring
on to lettrine
, in this fashion:
documentclass{article}
usepackage{times,lettrine,Eileen,coolstr,stringstrings,xstring}
newcommand*{first}[1]{substring[q]{#1}{1}{1}} %%% stringstrings version
newcommandflettrine[2]{first{#1}lettrine{thestring}{#2}}
begin{document}
flettrine{Whaaat}{hat} the duck? %%% DOES NOT WORK AS INTENDED WITH EILEEN
vspace{3em}
renewcommand*{LettrineFontHook}{Eileenfamily} %%% Eileen fancy drop letter WTF?
flettrine{What}{hat} the duck? %%% DOES NOT WORK AT ALL WITH EILEEN
end{document}
I recommend, in a case like this, doing it with raw TeX, without parsing packages.
documentclass{article}
usepackage{times,lettrine,Eileen}
deffirstaux#1#2relax{{#1}{#2}}
newcommandflettrine[1]{expandafterlettrinefirstaux#1relax}
begin{document}
flettrine{What} the duck?bigskip
renewcommand*{LettrineFontHook}{Eileenfamily}
flettrine{What} the duck?
end{document}
If you wanted to use stringstrings
for other reasons (more complex manipulations, for example), I would use substring
to store the result in thestring
, and then pass thestring
on to lettrine
, in this fashion:
documentclass{article}
usepackage{times,lettrine,Eileen,coolstr,stringstrings,xstring}
newcommand*{first}[1]{substring[q]{#1}{1}{1}} %%% stringstrings version
newcommandflettrine[2]{first{#1}lettrine{thestring}{#2}}
begin{document}
flettrine{Whaaat}{hat} the duck? %%% DOES NOT WORK AS INTENDED WITH EILEEN
vspace{3em}
renewcommand*{LettrineFontHook}{Eileenfamily} %%% Eileen fancy drop letter WTF?
flettrine{What}{hat} the duck? %%% DOES NOT WORK AT ALL WITH EILEEN
end{document}
edited 7 hours ago
answered 8 hours ago
Steven B. SegletesSteven B. Segletes
170k9 gold badges216 silver badges443 bronze badges
170k9 gold badges216 silver badges443 bronze badges
add a comment
|
add a comment
|
With expl3
it's really easy:
documentclass{article}
usepackage{newtxtext,lettrine,Eileen,xparse}
renewcommand*{LettrineFontHook}{Eileenfamily} %%% Eileen fancy drop letter WTF?
ExplSyntaxOn
NewDocumentCommand{IiroLettrine}{O{}m}
{
lettrine[#1]{tl_range:nnn { #2 } { 1 } { 1 }}{tl_range:nnn { #2 } { 2 } { -1 } }
}
ExplSyntaxOff
begin{document}
IiroLettrine{What} the duck?
end{document}
The problem with your code is that StrLeft{#1}{1}
doesn't produce the first letter, but the set of instructions for printing it, but lettrine
wants just a letter (after expansion).
The tl_range:nnn
function is fully expandable, so it makes no problem to lettrine
. With tl_range:nnn { #1 } { 1 } { 1 }
the first item in the argument is delivered; with tl_range:nnn { #1 } { 2 } { -1 }
the remaining items are produced (the negative second number means “up to the last item”).
Since small caps are needed, it's better to use newtxtext
that provides real small caps, instead of the faked ones you get with times
.
You can do it also with xstring
, using its trailing optional argument feature:
documentclass{article}
usepackage{newtxtext,lettrine,Eileen,xstring}
renewcommand*{LettrineFontHook}{Eileenfamily} %%% Eileen fancy drop letter WTF?
newcommand{IiroLettrine}[2][]{%
StrLeft{#2}{1}[firstletter]%
StrGobbleLeft{#2}{1}[otherletters]%
lettrine[#1]{firstletter}{otherletters}%
}
begin{document}
IiroLettrine{What} the duck?
end{document}
In both cases I kept the optional argument to lettrine
available in IiroLettrine
.
add a comment
|
With expl3
it's really easy:
documentclass{article}
usepackage{newtxtext,lettrine,Eileen,xparse}
renewcommand*{LettrineFontHook}{Eileenfamily} %%% Eileen fancy drop letter WTF?
ExplSyntaxOn
NewDocumentCommand{IiroLettrine}{O{}m}
{
lettrine[#1]{tl_range:nnn { #2 } { 1 } { 1 }}{tl_range:nnn { #2 } { 2 } { -1 } }
}
ExplSyntaxOff
begin{document}
IiroLettrine{What} the duck?
end{document}
The problem with your code is that StrLeft{#1}{1}
doesn't produce the first letter, but the set of instructions for printing it, but lettrine
wants just a letter (after expansion).
The tl_range:nnn
function is fully expandable, so it makes no problem to lettrine
. With tl_range:nnn { #1 } { 1 } { 1 }
the first item in the argument is delivered; with tl_range:nnn { #1 } { 2 } { -1 }
the remaining items are produced (the negative second number means “up to the last item”).
Since small caps are needed, it's better to use newtxtext
that provides real small caps, instead of the faked ones you get with times
.
You can do it also with xstring
, using its trailing optional argument feature:
documentclass{article}
usepackage{newtxtext,lettrine,Eileen,xstring}
renewcommand*{LettrineFontHook}{Eileenfamily} %%% Eileen fancy drop letter WTF?
newcommand{IiroLettrine}[2][]{%
StrLeft{#2}{1}[firstletter]%
StrGobbleLeft{#2}{1}[otherletters]%
lettrine[#1]{firstletter}{otherletters}%
}
begin{document}
IiroLettrine{What} the duck?
end{document}
In both cases I kept the optional argument to lettrine
available in IiroLettrine
.
add a comment
|
With expl3
it's really easy:
documentclass{article}
usepackage{newtxtext,lettrine,Eileen,xparse}
renewcommand*{LettrineFontHook}{Eileenfamily} %%% Eileen fancy drop letter WTF?
ExplSyntaxOn
NewDocumentCommand{IiroLettrine}{O{}m}
{
lettrine[#1]{tl_range:nnn { #2 } { 1 } { 1 }}{tl_range:nnn { #2 } { 2 } { -1 } }
}
ExplSyntaxOff
begin{document}
IiroLettrine{What} the duck?
end{document}
The problem with your code is that StrLeft{#1}{1}
doesn't produce the first letter, but the set of instructions for printing it, but lettrine
wants just a letter (after expansion).
The tl_range:nnn
function is fully expandable, so it makes no problem to lettrine
. With tl_range:nnn { #1 } { 1 } { 1 }
the first item in the argument is delivered; with tl_range:nnn { #1 } { 2 } { -1 }
the remaining items are produced (the negative second number means “up to the last item”).
Since small caps are needed, it's better to use newtxtext
that provides real small caps, instead of the faked ones you get with times
.
You can do it also with xstring
, using its trailing optional argument feature:
documentclass{article}
usepackage{newtxtext,lettrine,Eileen,xstring}
renewcommand*{LettrineFontHook}{Eileenfamily} %%% Eileen fancy drop letter WTF?
newcommand{IiroLettrine}[2][]{%
StrLeft{#2}{1}[firstletter]%
StrGobbleLeft{#2}{1}[otherletters]%
lettrine[#1]{firstletter}{otherletters}%
}
begin{document}
IiroLettrine{What} the duck?
end{document}
In both cases I kept the optional argument to lettrine
available in IiroLettrine
.
With expl3
it's really easy:
documentclass{article}
usepackage{newtxtext,lettrine,Eileen,xparse}
renewcommand*{LettrineFontHook}{Eileenfamily} %%% Eileen fancy drop letter WTF?
ExplSyntaxOn
NewDocumentCommand{IiroLettrine}{O{}m}
{
lettrine[#1]{tl_range:nnn { #2 } { 1 } { 1 }}{tl_range:nnn { #2 } { 2 } { -1 } }
}
ExplSyntaxOff
begin{document}
IiroLettrine{What} the duck?
end{document}
The problem with your code is that StrLeft{#1}{1}
doesn't produce the first letter, but the set of instructions for printing it, but lettrine
wants just a letter (after expansion).
The tl_range:nnn
function is fully expandable, so it makes no problem to lettrine
. With tl_range:nnn { #1 } { 1 } { 1 }
the first item in the argument is delivered; with tl_range:nnn { #1 } { 2 } { -1 }
the remaining items are produced (the negative second number means “up to the last item”).
Since small caps are needed, it's better to use newtxtext
that provides real small caps, instead of the faked ones you get with times
.
You can do it also with xstring
, using its trailing optional argument feature:
documentclass{article}
usepackage{newtxtext,lettrine,Eileen,xstring}
renewcommand*{LettrineFontHook}{Eileenfamily} %%% Eileen fancy drop letter WTF?
newcommand{IiroLettrine}[2][]{%
StrLeft{#2}{1}[firstletter]%
StrGobbleLeft{#2}{1}[otherletters]%
lettrine[#1]{firstletter}{otherletters}%
}
begin{document}
IiroLettrine{What} the duck?
end{document}
In both cases I kept the optional argument to lettrine
available in IiroLettrine
.
answered 4 hours ago
egregegreg
770k91 gold badges2011 silver badges3367 bronze badges
770k91 gold badges2011 silver badges3367 bronze badges
add a comment
|
add a comment
|
Iiro Ullin is a new contributor. Be nice, and check out our Code of Conduct.
Iiro Ullin is a new contributor. Be nice, and check out our Code of Conduct.
Iiro Ullin is a new contributor. Be nice, and check out our Code of Conduct.
Iiro Ullin is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f509105%2flettrine-string-manipulation-some-fonts-errors-and-weird-issues%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I understand your goals and they are noble. However, when I wanted to use
lettrine
(and had no time), I just definednewcommand{flx}[2]{lettrine[lines=4,realheight=true]{#1}{textsc{#2}}}
and did the separation in first letter and remaning part myself. You uselettrine
once per chapter, it's not that much work.– Oleg Lobachev
7 hours ago
1
Oleg: thanks for responding, however, this would not work for me, as the presented piece of code is just for illustration purposes. My actual code does the parsing automatically and has to extract first letters from words on its own. I've accepted Steven B. Segletes' answer, as not only it fixes the problem, but also teaches some TeX programming :) Thank you, Steven!
– Iiro Ullin
7 hours ago