Changing the font based on availability to fontspec
I would like to distribute a class that uses a professional font loaded via fontspec, and falls back to one of the default fonts in TeX Live if this is not available. I know that one can detect fonts packaged with TeX Live:
documentclass{article}
usepackage{fontspec}
IfFileExists{tgpagella.sty}{setmainfont{TeX Gyre Pagella}}{}
begin{document}
fontnamefont at thefontdimen6font
end{document}
This doesn't work, however, if one instead tries to detect a font file in the same directory:
documentclass{article}
usepackage{fontspec}
IfFileExists{texgyrepagella-regular.otf}{setmainfont{TeX Gyre Pagella}}{}
begin{document}
fontnamefont at thefontdimen6font
end{document}
Is there a mechanism somewhere to include .otf
files in what IfFileExists
is able to detect?
fonts fontspec
|
show 2 more comments
I would like to distribute a class that uses a professional font loaded via fontspec, and falls back to one of the default fonts in TeX Live if this is not available. I know that one can detect fonts packaged with TeX Live:
documentclass{article}
usepackage{fontspec}
IfFileExists{tgpagella.sty}{setmainfont{TeX Gyre Pagella}}{}
begin{document}
fontnamefont at thefontdimen6font
end{document}
This doesn't work, however, if one instead tries to detect a font file in the same directory:
documentclass{article}
usepackage{fontspec}
IfFileExists{texgyrepagella-regular.otf}{setmainfont{TeX Gyre Pagella}}{}
begin{document}
fontnamefont at thefontdimen6font
end{document}
Is there a mechanism somewhere to include .otf
files in what IfFileExists
is able to detect?
fonts fontspec
fontspec has a fallback mechanism these days older answer but Will added a proper interface to that if I recall correctly
– David Carlisle
Jan 21 at 16:38
1
fontspec_font_if_exist:nTF
and similar commands look to be the right thing....
– David Carlisle
Jan 21 at 16:43
1
@DavidCarlisle the documentation suggestsIfFontExistsTF
.
– Ulrike Fischer
Jan 21 at 16:44
5
@UlrikeFischer but it looks much more impressive with_
and:
– David Carlisle
Jan 21 at 16:45
Brilliant; thank you both!
– Andrew Dunning
Jan 21 at 16:46
|
show 2 more comments
I would like to distribute a class that uses a professional font loaded via fontspec, and falls back to one of the default fonts in TeX Live if this is not available. I know that one can detect fonts packaged with TeX Live:
documentclass{article}
usepackage{fontspec}
IfFileExists{tgpagella.sty}{setmainfont{TeX Gyre Pagella}}{}
begin{document}
fontnamefont at thefontdimen6font
end{document}
This doesn't work, however, if one instead tries to detect a font file in the same directory:
documentclass{article}
usepackage{fontspec}
IfFileExists{texgyrepagella-regular.otf}{setmainfont{TeX Gyre Pagella}}{}
begin{document}
fontnamefont at thefontdimen6font
end{document}
Is there a mechanism somewhere to include .otf
files in what IfFileExists
is able to detect?
fonts fontspec
I would like to distribute a class that uses a professional font loaded via fontspec, and falls back to one of the default fonts in TeX Live if this is not available. I know that one can detect fonts packaged with TeX Live:
documentclass{article}
usepackage{fontspec}
IfFileExists{tgpagella.sty}{setmainfont{TeX Gyre Pagella}}{}
begin{document}
fontnamefont at thefontdimen6font
end{document}
This doesn't work, however, if one instead tries to detect a font file in the same directory:
documentclass{article}
usepackage{fontspec}
IfFileExists{texgyrepagella-regular.otf}{setmainfont{TeX Gyre Pagella}}{}
begin{document}
fontnamefont at thefontdimen6font
end{document}
Is there a mechanism somewhere to include .otf
files in what IfFileExists
is able to detect?
fonts fontspec
fonts fontspec
asked Jan 21 at 16:16
Andrew DunningAndrew Dunning
578214
578214
fontspec has a fallback mechanism these days older answer but Will added a proper interface to that if I recall correctly
– David Carlisle
Jan 21 at 16:38
1
fontspec_font_if_exist:nTF
and similar commands look to be the right thing....
– David Carlisle
Jan 21 at 16:43
1
@DavidCarlisle the documentation suggestsIfFontExistsTF
.
– Ulrike Fischer
Jan 21 at 16:44
5
@UlrikeFischer but it looks much more impressive with_
and:
– David Carlisle
Jan 21 at 16:45
Brilliant; thank you both!
– Andrew Dunning
Jan 21 at 16:46
|
show 2 more comments
fontspec has a fallback mechanism these days older answer but Will added a proper interface to that if I recall correctly
– David Carlisle
Jan 21 at 16:38
1
fontspec_font_if_exist:nTF
and similar commands look to be the right thing....
– David Carlisle
Jan 21 at 16:43
1
@DavidCarlisle the documentation suggestsIfFontExistsTF
.
– Ulrike Fischer
Jan 21 at 16:44
5
@UlrikeFischer but it looks much more impressive with_
and:
– David Carlisle
Jan 21 at 16:45
Brilliant; thank you both!
– Andrew Dunning
Jan 21 at 16:46
fontspec has a fallback mechanism these days older answer but Will added a proper interface to that if I recall correctly
– David Carlisle
Jan 21 at 16:38
fontspec has a fallback mechanism these days older answer but Will added a proper interface to that if I recall correctly
– David Carlisle
Jan 21 at 16:38
1
1
fontspec_font_if_exist:nTF
and similar commands look to be the right thing....– David Carlisle
Jan 21 at 16:43
fontspec_font_if_exist:nTF
and similar commands look to be the right thing....– David Carlisle
Jan 21 at 16:43
1
1
@DavidCarlisle the documentation suggests
IfFontExistsTF
.– Ulrike Fischer
Jan 21 at 16:44
@DavidCarlisle the documentation suggests
IfFontExistsTF
.– Ulrike Fischer
Jan 21 at 16:44
5
5
@UlrikeFischer but it looks much more impressive with
_
and :
– David Carlisle
Jan 21 at 16:45
@UlrikeFischer but it looks much more impressive with
_
and :
– David Carlisle
Jan 21 at 16:45
Brilliant; thank you both!
– Andrew Dunning
Jan 21 at 16:46
Brilliant; thank you both!
– Andrew Dunning
Jan 21 at 16:46
|
show 2 more comments
1 Answer
1
active
oldest
votes
Recent fontspec
releases allow you to test for a font being loadable with IfFontExistsTF
or its internal expl3
version fontspec_font_if_exist:nTF
:
documentclass{article}
usepackage{fontspec}
IfFontExistsTF{texgyrepagella-regular.otf}{setmainfont{TeX Gyre Pagella}}{}
begin{document}
fontnamefont at thefontdimen6font
end{document}
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/3.0/"u003ecc by-sa 3.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
});
}
});
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%2f471157%2fchanging-the-font-based-on-availability-to-fontspec%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Recent fontspec
releases allow you to test for a font being loadable with IfFontExistsTF
or its internal expl3
version fontspec_font_if_exist:nTF
:
documentclass{article}
usepackage{fontspec}
IfFontExistsTF{texgyrepagella-regular.otf}{setmainfont{TeX Gyre Pagella}}{}
begin{document}
fontnamefont at thefontdimen6font
end{document}
add a comment |
Recent fontspec
releases allow you to test for a font being loadable with IfFontExistsTF
or its internal expl3
version fontspec_font_if_exist:nTF
:
documentclass{article}
usepackage{fontspec}
IfFontExistsTF{texgyrepagella-regular.otf}{setmainfont{TeX Gyre Pagella}}{}
begin{document}
fontnamefont at thefontdimen6font
end{document}
add a comment |
Recent fontspec
releases allow you to test for a font being loadable with IfFontExistsTF
or its internal expl3
version fontspec_font_if_exist:nTF
:
documentclass{article}
usepackage{fontspec}
IfFontExistsTF{texgyrepagella-regular.otf}{setmainfont{TeX Gyre Pagella}}{}
begin{document}
fontnamefont at thefontdimen6font
end{document}
Recent fontspec
releases allow you to test for a font being loadable with IfFontExistsTF
or its internal expl3
version fontspec_font_if_exist:nTF
:
documentclass{article}
usepackage{fontspec}
IfFontExistsTF{texgyrepagella-regular.otf}{setmainfont{TeX Gyre Pagella}}{}
begin{document}
fontnamefont at thefontdimen6font
end{document}
edited Jan 21 at 19:23
Andrew Dunning
578214
578214
answered Jan 21 at 17:26
David CarlisleDavid Carlisle
490k4111321881
490k4111321881
add a comment |
add a comment |
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%2f471157%2fchanging-the-font-based-on-availability-to-fontspec%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
fontspec has a fallback mechanism these days older answer but Will added a proper interface to that if I recall correctly
– David Carlisle
Jan 21 at 16:38
1
fontspec_font_if_exist:nTF
and similar commands look to be the right thing....– David Carlisle
Jan 21 at 16:43
1
@DavidCarlisle the documentation suggests
IfFontExistsTF
.– Ulrike Fischer
Jan 21 at 16:44
5
@UlrikeFischer but it looks much more impressive with
_
and:
– David Carlisle
Jan 21 at 16:45
Brilliant; thank you both!
– Andrew Dunning
Jan 21 at 16:46