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
2 days ago
1
fontspec_font_if_exist:nTF
and similar commands look to be the right thing....
– David Carlisle
2 days ago
1
@DavidCarlisle the documentation suggestsIfFontExistsTF
.
– Ulrike Fischer
2 days ago
5
@UlrikeFischer but it looks much more impressive with_
and:
– David Carlisle
2 days ago
Brilliant; thank you both!
– Andrew Dunning
2 days ago
|
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 2 days ago
Andrew DunningAndrew Dunning
532212
532212
fontspec has a fallback mechanism these days older answer but Will added a proper interface to that if I recall correctly
– David Carlisle
2 days ago
1
fontspec_font_if_exist:nTF
and similar commands look to be the right thing....
– David Carlisle
2 days ago
1
@DavidCarlisle the documentation suggestsIfFontExistsTF
.
– Ulrike Fischer
2 days ago
5
@UlrikeFischer but it looks much more impressive with_
and:
– David Carlisle
2 days ago
Brilliant; thank you both!
– Andrew Dunning
2 days ago
|
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
2 days ago
1
fontspec_font_if_exist:nTF
and similar commands look to be the right thing....
– David Carlisle
2 days ago
1
@DavidCarlisle the documentation suggestsIfFontExistsTF
.
– Ulrike Fischer
2 days ago
5
@UlrikeFischer but it looks much more impressive with_
and:
– David Carlisle
2 days ago
Brilliant; thank you both!
– Andrew Dunning
2 days ago
fontspec has a fallback mechanism these days older answer but Will added a proper interface to that if I recall correctly
– David Carlisle
2 days ago
fontspec has a fallback mechanism these days older answer but Will added a proper interface to that if I recall correctly
– David Carlisle
2 days ago
1
1
fontspec_font_if_exist:nTF
and similar commands look to be the right thing....– David Carlisle
2 days ago
fontspec_font_if_exist:nTF
and similar commands look to be the right thing....– David Carlisle
2 days ago
1
1
@DavidCarlisle the documentation suggests
IfFontExistsTF
.– Ulrike Fischer
2 days ago
@DavidCarlisle the documentation suggests
IfFontExistsTF
.– Ulrike Fischer
2 days ago
5
5
@UlrikeFischer but it looks much more impressive with
_
and :
– David Carlisle
2 days ago
@UlrikeFischer but it looks much more impressive with
_
and :
– David Carlisle
2 days ago
Brilliant; thank you both!
– Andrew Dunning
2 days ago
Brilliant; thank you both!
– Andrew Dunning
2 days ago
|
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 2 days ago
Andrew Dunning
532212
532212
answered 2 days ago
David CarlisleDavid Carlisle
486k4111231867
486k4111231867
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
2 days ago
1
fontspec_font_if_exist:nTF
and similar commands look to be the right thing....– David Carlisle
2 days ago
1
@DavidCarlisle the documentation suggests
IfFontExistsTF
.– Ulrike Fischer
2 days ago
5
@UlrikeFischer but it looks much more impressive with
_
and:
– David Carlisle
2 days ago
Brilliant; thank you both!
– Andrew Dunning
2 days ago