How to replace photo in moderncv classic with a QR code?
I am making my resume using the moderncv package with the classic style.
I wish to replace the photo with a QR-code to my personal website, using the qrcode package.
I tried replacing the argument of the photo command with the corresponding qrcode{...} command, but this fails with a LaTeX error message.
Here is a MWE that illustrates the idea I am trying
documentclass[11pt,a4paper,sans]{moderncv}
moderncvstyle{classic}
usepackage{graphicx}
usepackage{qrcode}
firstname{John}
familyname{Doe}
address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
phone[mobile]{123 456 7890}
email{someone@xyz.com}
% photo[64pt][0.5pt]{example-image-a} % works fine
photo[64pt][0.5pt]{qrcode[hyperlink,height=64pt]{http://www.ctan.org}} % produces an error
begin{document}
makecvtitle
end{document}
How can I achieve the desired goal?
Update
I now understand that photo is essentialy a wrapper for includegraphics, and therefore expects a file path as its argument.
Is it possible to re-define
phototo be flexible enough to accept either alatexcommand or a graphics file path?Failing that, at least is it possible to automate the inclusion of a QR-code image that automatically updates whenever the URL argument to the
qrcodecommand is updated i.e. avoid compilation of multiple documents?
graphics moderncv includegraphics qrcode
|
show 8 more comments
I am making my resume using the moderncv package with the classic style.
I wish to replace the photo with a QR-code to my personal website, using the qrcode package.
I tried replacing the argument of the photo command with the corresponding qrcode{...} command, but this fails with a LaTeX error message.
Here is a MWE that illustrates the idea I am trying
documentclass[11pt,a4paper,sans]{moderncv}
moderncvstyle{classic}
usepackage{graphicx}
usepackage{qrcode}
firstname{John}
familyname{Doe}
address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
phone[mobile]{123 456 7890}
email{someone@xyz.com}
% photo[64pt][0.5pt]{example-image-a} % works fine
photo[64pt][0.5pt]{qrcode[hyperlink,height=64pt]{http://www.ctan.org}} % produces an error
begin{document}
makecvtitle
end{document}
How can I achieve the desired goal?
Update
I now understand that photo is essentialy a wrapper for includegraphics, and therefore expects a file path as its argument.
Is it possible to re-define
phototo be flexible enough to accept either alatexcommand or a graphics file path?Failing that, at least is it possible to automate the inclusion of a QR-code image that automatically updates whenever the URL argument to the
qrcodecommand is updated i.e. avoid compilation of multiple documents?
graphics moderncv includegraphics qrcode
Are you loading theqrcodepackage? I don't think moderncv loads it, or at least it didn't last time I checked, which was a few years ago
– Chris H
6 hours ago
@ChrisH yes, myMWEforgot to include it. Updated themwesuitably. The errror is not due to this.
– Krishna
6 hours ago
It seems that the argument ofphotois a graphics file, not a LaTeX command. Have you tried to compile the qrcode to a pdf file, and to include the latter?
– marmot
6 hours ago
@marmot that doesn't sound like an elegant option to me. Is it possible to redefinephototo accept both LaTeX commands as well as as image file paths?
– Krishna
6 hours ago
@marmot If I want to update theqr codein the future, I have to remember to re-compile the qr code image. That's tedious and error-prone. At the very least can we have one single compilation that automatically updates the image whenever theqrcodecommand arguments are updated?
– Krishna
6 hours ago
|
show 8 more comments
I am making my resume using the moderncv package with the classic style.
I wish to replace the photo with a QR-code to my personal website, using the qrcode package.
I tried replacing the argument of the photo command with the corresponding qrcode{...} command, but this fails with a LaTeX error message.
Here is a MWE that illustrates the idea I am trying
documentclass[11pt,a4paper,sans]{moderncv}
moderncvstyle{classic}
usepackage{graphicx}
usepackage{qrcode}
firstname{John}
familyname{Doe}
address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
phone[mobile]{123 456 7890}
email{someone@xyz.com}
% photo[64pt][0.5pt]{example-image-a} % works fine
photo[64pt][0.5pt]{qrcode[hyperlink,height=64pt]{http://www.ctan.org}} % produces an error
begin{document}
makecvtitle
end{document}
How can I achieve the desired goal?
Update
I now understand that photo is essentialy a wrapper for includegraphics, and therefore expects a file path as its argument.
Is it possible to re-define
phototo be flexible enough to accept either alatexcommand or a graphics file path?Failing that, at least is it possible to automate the inclusion of a QR-code image that automatically updates whenever the URL argument to the
qrcodecommand is updated i.e. avoid compilation of multiple documents?
graphics moderncv includegraphics qrcode
I am making my resume using the moderncv package with the classic style.
I wish to replace the photo with a QR-code to my personal website, using the qrcode package.
I tried replacing the argument of the photo command with the corresponding qrcode{...} command, but this fails with a LaTeX error message.
Here is a MWE that illustrates the idea I am trying
documentclass[11pt,a4paper,sans]{moderncv}
moderncvstyle{classic}
usepackage{graphicx}
usepackage{qrcode}
firstname{John}
familyname{Doe}
address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
phone[mobile]{123 456 7890}
email{someone@xyz.com}
% photo[64pt][0.5pt]{example-image-a} % works fine
photo[64pt][0.5pt]{qrcode[hyperlink,height=64pt]{http://www.ctan.org}} % produces an error
begin{document}
makecvtitle
end{document}
How can I achieve the desired goal?
Update
I now understand that photo is essentialy a wrapper for includegraphics, and therefore expects a file path as its argument.
Is it possible to re-define
phototo be flexible enough to accept either alatexcommand or a graphics file path?Failing that, at least is it possible to automate the inclusion of a QR-code image that automatically updates whenever the URL argument to the
qrcodecommand is updated i.e. avoid compilation of multiple documents?
graphics moderncv includegraphics qrcode
graphics moderncv includegraphics qrcode
edited 6 hours ago
Krishna
asked 7 hours ago
KrishnaKrishna
1,105620
1,105620
Are you loading theqrcodepackage? I don't think moderncv loads it, or at least it didn't last time I checked, which was a few years ago
– Chris H
6 hours ago
@ChrisH yes, myMWEforgot to include it. Updated themwesuitably. The errror is not due to this.
– Krishna
6 hours ago
It seems that the argument ofphotois a graphics file, not a LaTeX command. Have you tried to compile the qrcode to a pdf file, and to include the latter?
– marmot
6 hours ago
@marmot that doesn't sound like an elegant option to me. Is it possible to redefinephototo accept both LaTeX commands as well as as image file paths?
– Krishna
6 hours ago
@marmot If I want to update theqr codein the future, I have to remember to re-compile the qr code image. That's tedious and error-prone. At the very least can we have one single compilation that automatically updates the image whenever theqrcodecommand arguments are updated?
– Krishna
6 hours ago
|
show 8 more comments
Are you loading theqrcodepackage? I don't think moderncv loads it, or at least it didn't last time I checked, which was a few years ago
– Chris H
6 hours ago
@ChrisH yes, myMWEforgot to include it. Updated themwesuitably. The errror is not due to this.
– Krishna
6 hours ago
It seems that the argument ofphotois a graphics file, not a LaTeX command. Have you tried to compile the qrcode to a pdf file, and to include the latter?
– marmot
6 hours ago
@marmot that doesn't sound like an elegant option to me. Is it possible to redefinephototo accept both LaTeX commands as well as as image file paths?
– Krishna
6 hours ago
@marmot If I want to update theqr codein the future, I have to remember to re-compile the qr code image. That's tedious and error-prone. At the very least can we have one single compilation that automatically updates the image whenever theqrcodecommand arguments are updated?
– Krishna
6 hours ago
Are you loading the
qrcode package? I don't think moderncv loads it, or at least it didn't last time I checked, which was a few years ago– Chris H
6 hours ago
Are you loading the
qrcode package? I don't think moderncv loads it, or at least it didn't last time I checked, which was a few years ago– Chris H
6 hours ago
@ChrisH yes, my
MWE forgot to include it. Updated the mwe suitably. The errror is not due to this.– Krishna
6 hours ago
@ChrisH yes, my
MWE forgot to include it. Updated the mwe suitably. The errror is not due to this.– Krishna
6 hours ago
It seems that the argument of
photo is a graphics file, not a LaTeX command. Have you tried to compile the qrcode to a pdf file, and to include the latter?– marmot
6 hours ago
It seems that the argument of
photo is a graphics file, not a LaTeX command. Have you tried to compile the qrcode to a pdf file, and to include the latter?– marmot
6 hours ago
@marmot that doesn't sound like an elegant option to me. Is it possible to redefine
photo to accept both LaTeX commands as well as as image file paths?– Krishna
6 hours ago
@marmot that doesn't sound like an elegant option to me. Is it possible to redefine
photo to accept both LaTeX commands as well as as image file paths?– Krishna
6 hours ago
@marmot If I want to update the
qr code in the future, I have to remember to re-compile the qr code image. That's tedious and error-prone. At the very least can we have one single compilation that automatically updates the image whenever the qrcode command arguments are updated?– Krishna
6 hours ago
@marmot If I want to update the
qr code in the future, I have to remember to re-compile the qr code image. That's tedious and error-prone. At the very least can we have one single compilation that automatically updates the image whenever the qrcode command arguments are updated?– Krishna
6 hours ago
|
show 8 more comments
2 Answers
2
active
oldest
votes
photo command wants a file suitable to be included with an includegraphics command. Therefore, I think the easiest solution would be to create your own qrcode within an standalone document and use the result as photo in moderncv.
%File qrcode.tex -> qrcode.pdf
documentclass{standalone}
usepackage{qrcode}
begin{document}
qrcode[hyperlink,height=64pt]{http://www.ctan.org}
end{document}

documentclass[11pt,a4paper,sans]{moderncv}
moderncvstyle{classic}
usepackage{qrcode}
usepackage{graphicx}
firstname{John}
familyname{Doe}
address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
phone[mobile]{123 456 7890}
email{someone@xyz.com}
photo[64pt][0.5pt]{qrcode}
begin{document}
makecvtitle
end{document}

Update: All in one ;-)
With filecontents package and an immediate command it's possible to join both files into one and compile both together:
documentclass[11pt,a4paper,sans]{moderncv}
moderncvstyle{classic}
usepackage{qrcode}
usepackage{filecontents}
begin{filecontents*}{myqrcode.tex} %<- This is the qrcode file name
documentclass{standalone}
usepackage{qrcode}
begin{document}
qrcode[hyperlink,height=64pt]{http://www.ctan.org}
end{document}
end{filecontents*}
immediatewrite18{pdflatex myqrcode.tex}
firstname{John}
familyname{Doe}
address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
phone[mobile]{123 456 7890}
email{someone@xyz.com}
photo[64pt][0.5pt]{myqrcode} %<- Insert previous name
begin{document}
makecvtitle
end{document}
@lgnasi thank you. But this does not look like a nice option.Is it possible to redefinephototo accept both LaTeX commands as well as as image file paths? If I want to update theqr codein the future, I have to remember to compile the original image. That's tedious and error-prone. At the very least can we have one single compilation that automatically updates the image whenever theqrcodecommand arguments are updated?
– Krishna
6 hours ago
@Krishna You can do it withfilecontentshelp. See my updated answer.
– Ignasi
6 hours ago
@lgnasi Yes, just finished trying your combined solution with thefilecontentspackage. It works! Thank you. Upvoted and marked as accepted.
– Krishna
5 hours ago
add a comment |
In the code of class moderncv, style classic you can find an if-then-else construct checking if a photo is defined (printing it) or not (doing nothing). I added inside the empty case a new if-then-else testing, if a new command qrphoto is defined. If it is defined the code prints it, in the other case it does nothing.
The new command for the qrphoto is:
NewDocumentCommand{qrphoto}{O{64pt}O{0.4pt}m}{def@qrphotowidth{#1}def@qrphotoframewidth{#2}def@qrphoto{#3}}
With this command I define the needed values @qrphotowidth etc. for later usage.
Now we can patch the original command with
patchcmd{makecvhead}%
{%
ifthenelse{isundefined{@photo}}{}%
}% code to patch
{% new code <=========================================================
ifthenelse{isundefined{@photo}}%
{%
ifthenelse{isundefined{@qrphoto}}%
{}%
{%
if@left%
hspace*{separatorcolumnwidth}fi%
color{color1}%
setlength{fboxrule}{@qrphotoframewidth}%
ifdim@qrphotoframewidth=0pt%
setlength{fboxsep}{0pt}fi%
raisebox{1cm}{framebox{qrcode[hyperlink,height=@qrphotowidth]{@qrphoto}}}
}
}%
}% end new code <=====================================================
{}% success
{fail}% failure
The command raisebox[1cm] is needed to get the qr-code on the right position (I did not search for the reason, why I need it here. The used value is okay for sizes of the resulting qr-code of 2cm (I used for the example code) or more. If your qr-code should be smaller you need to change my used value of 1cm to a lower value. You will have to try it out.
As you can see I deleted the command includegraphics. With command qrphoto qrcode... from package qrcode.
With the command
qrphoto[2cm][0.5pt]{https://tex.stackexchange.com/questions/474546/}
for example you can add an qr-code-image with a hight and width of 2cm, a frame around it with a line of 0.5pt and the content of the qr-code-image is https://tex.stackexchange.com/questions/474546/ (this question).
So with the following complete MWE
documentclass[11pt,a4paper,sans]{moderncv}
moderncvstyle{classic}
usepackage{graphicx}
usepackage{qrcode}
firstname{John}
familyname{Doe}
address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
phone[mobile]{123 456 7890}
email{someone@xyz.com}
makeatletter
NewDocumentCommand{qrphoto}{O{64pt}O{0.4pt}m}{def@qrphotowidth{#1}def@qrphotoframewidth{#2}def@qrphoto{#3}}
% to patch the code of moderncv, version 2.0.0
%usepackage{etoolbox} % already loaded in moderncv <===================
patchcmd{makecvhead}%
{%
ifthenelse{isundefined{@photo}}{}%
}% code to patch
{% new code <=========================================================
ifthenelse{isundefined{@photo}}%
{%
ifthenelse{isundefined{@qrphoto}}%
{}%
{%
if@left%
hspace*{separatorcolumnwidth}fi%
color{color1}%
setlength{fboxrule}{@qrphotoframewidth}%
ifdim@qrphotoframewidth=0pt%
setlength{fboxsep}{0pt}fi%
raisebox{1cm}{framebox{qrcode[hyperlink,height=@qrphotowidth]{@qrphoto}}}
}
}%
}% end new code <=====================================================
{}% success
{fail}% failure
makeatother
%photo[64pt][0.5pt]{example-image}
qrphoto[2cm][0.5pt]{https://tex.stackexchange.com/questions/474546/} %
begin{document}
makecvtitle
end{document}
you get the following result:

Please note that you can only print a photo or a qr-code. If you have a defined photo and qrphoto only the photo is printed!
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%2f474546%2fhow-to-replace-photo-in-moderncv-classic-with-a-qr-code%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
photo command wants a file suitable to be included with an includegraphics command. Therefore, I think the easiest solution would be to create your own qrcode within an standalone document and use the result as photo in moderncv.
%File qrcode.tex -> qrcode.pdf
documentclass{standalone}
usepackage{qrcode}
begin{document}
qrcode[hyperlink,height=64pt]{http://www.ctan.org}
end{document}

documentclass[11pt,a4paper,sans]{moderncv}
moderncvstyle{classic}
usepackage{qrcode}
usepackage{graphicx}
firstname{John}
familyname{Doe}
address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
phone[mobile]{123 456 7890}
email{someone@xyz.com}
photo[64pt][0.5pt]{qrcode}
begin{document}
makecvtitle
end{document}

Update: All in one ;-)
With filecontents package and an immediate command it's possible to join both files into one and compile both together:
documentclass[11pt,a4paper,sans]{moderncv}
moderncvstyle{classic}
usepackage{qrcode}
usepackage{filecontents}
begin{filecontents*}{myqrcode.tex} %<- This is the qrcode file name
documentclass{standalone}
usepackage{qrcode}
begin{document}
qrcode[hyperlink,height=64pt]{http://www.ctan.org}
end{document}
end{filecontents*}
immediatewrite18{pdflatex myqrcode.tex}
firstname{John}
familyname{Doe}
address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
phone[mobile]{123 456 7890}
email{someone@xyz.com}
photo[64pt][0.5pt]{myqrcode} %<- Insert previous name
begin{document}
makecvtitle
end{document}
@lgnasi thank you. But this does not look like a nice option.Is it possible to redefinephototo accept both LaTeX commands as well as as image file paths? If I want to update theqr codein the future, I have to remember to compile the original image. That's tedious and error-prone. At the very least can we have one single compilation that automatically updates the image whenever theqrcodecommand arguments are updated?
– Krishna
6 hours ago
@Krishna You can do it withfilecontentshelp. See my updated answer.
– Ignasi
6 hours ago
@lgnasi Yes, just finished trying your combined solution with thefilecontentspackage. It works! Thank you. Upvoted and marked as accepted.
– Krishna
5 hours ago
add a comment |
photo command wants a file suitable to be included with an includegraphics command. Therefore, I think the easiest solution would be to create your own qrcode within an standalone document and use the result as photo in moderncv.
%File qrcode.tex -> qrcode.pdf
documentclass{standalone}
usepackage{qrcode}
begin{document}
qrcode[hyperlink,height=64pt]{http://www.ctan.org}
end{document}

documentclass[11pt,a4paper,sans]{moderncv}
moderncvstyle{classic}
usepackage{qrcode}
usepackage{graphicx}
firstname{John}
familyname{Doe}
address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
phone[mobile]{123 456 7890}
email{someone@xyz.com}
photo[64pt][0.5pt]{qrcode}
begin{document}
makecvtitle
end{document}

Update: All in one ;-)
With filecontents package and an immediate command it's possible to join both files into one and compile both together:
documentclass[11pt,a4paper,sans]{moderncv}
moderncvstyle{classic}
usepackage{qrcode}
usepackage{filecontents}
begin{filecontents*}{myqrcode.tex} %<- This is the qrcode file name
documentclass{standalone}
usepackage{qrcode}
begin{document}
qrcode[hyperlink,height=64pt]{http://www.ctan.org}
end{document}
end{filecontents*}
immediatewrite18{pdflatex myqrcode.tex}
firstname{John}
familyname{Doe}
address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
phone[mobile]{123 456 7890}
email{someone@xyz.com}
photo[64pt][0.5pt]{myqrcode} %<- Insert previous name
begin{document}
makecvtitle
end{document}
@lgnasi thank you. But this does not look like a nice option.Is it possible to redefinephototo accept both LaTeX commands as well as as image file paths? If I want to update theqr codein the future, I have to remember to compile the original image. That's tedious and error-prone. At the very least can we have one single compilation that automatically updates the image whenever theqrcodecommand arguments are updated?
– Krishna
6 hours ago
@Krishna You can do it withfilecontentshelp. See my updated answer.
– Ignasi
6 hours ago
@lgnasi Yes, just finished trying your combined solution with thefilecontentspackage. It works! Thank you. Upvoted and marked as accepted.
– Krishna
5 hours ago
add a comment |
photo command wants a file suitable to be included with an includegraphics command. Therefore, I think the easiest solution would be to create your own qrcode within an standalone document and use the result as photo in moderncv.
%File qrcode.tex -> qrcode.pdf
documentclass{standalone}
usepackage{qrcode}
begin{document}
qrcode[hyperlink,height=64pt]{http://www.ctan.org}
end{document}

documentclass[11pt,a4paper,sans]{moderncv}
moderncvstyle{classic}
usepackage{qrcode}
usepackage{graphicx}
firstname{John}
familyname{Doe}
address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
phone[mobile]{123 456 7890}
email{someone@xyz.com}
photo[64pt][0.5pt]{qrcode}
begin{document}
makecvtitle
end{document}

Update: All in one ;-)
With filecontents package and an immediate command it's possible to join both files into one and compile both together:
documentclass[11pt,a4paper,sans]{moderncv}
moderncvstyle{classic}
usepackage{qrcode}
usepackage{filecontents}
begin{filecontents*}{myqrcode.tex} %<- This is the qrcode file name
documentclass{standalone}
usepackage{qrcode}
begin{document}
qrcode[hyperlink,height=64pt]{http://www.ctan.org}
end{document}
end{filecontents*}
immediatewrite18{pdflatex myqrcode.tex}
firstname{John}
familyname{Doe}
address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
phone[mobile]{123 456 7890}
email{someone@xyz.com}
photo[64pt][0.5pt]{myqrcode} %<- Insert previous name
begin{document}
makecvtitle
end{document}
photo command wants a file suitable to be included with an includegraphics command. Therefore, I think the easiest solution would be to create your own qrcode within an standalone document and use the result as photo in moderncv.
%File qrcode.tex -> qrcode.pdf
documentclass{standalone}
usepackage{qrcode}
begin{document}
qrcode[hyperlink,height=64pt]{http://www.ctan.org}
end{document}

documentclass[11pt,a4paper,sans]{moderncv}
moderncvstyle{classic}
usepackage{qrcode}
usepackage{graphicx}
firstname{John}
familyname{Doe}
address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
phone[mobile]{123 456 7890}
email{someone@xyz.com}
photo[64pt][0.5pt]{qrcode}
begin{document}
makecvtitle
end{document}

Update: All in one ;-)
With filecontents package and an immediate command it's possible to join both files into one and compile both together:
documentclass[11pt,a4paper,sans]{moderncv}
moderncvstyle{classic}
usepackage{qrcode}
usepackage{filecontents}
begin{filecontents*}{myqrcode.tex} %<- This is the qrcode file name
documentclass{standalone}
usepackage{qrcode}
begin{document}
qrcode[hyperlink,height=64pt]{http://www.ctan.org}
end{document}
end{filecontents*}
immediatewrite18{pdflatex myqrcode.tex}
firstname{John}
familyname{Doe}
address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
phone[mobile]{123 456 7890}
email{someone@xyz.com}
photo[64pt][0.5pt]{myqrcode} %<- Insert previous name
begin{document}
makecvtitle
end{document}
edited 6 hours ago
answered 6 hours ago
IgnasiIgnasi
93.2k4167310
93.2k4167310
@lgnasi thank you. But this does not look like a nice option.Is it possible to redefinephototo accept both LaTeX commands as well as as image file paths? If I want to update theqr codein the future, I have to remember to compile the original image. That's tedious and error-prone. At the very least can we have one single compilation that automatically updates the image whenever theqrcodecommand arguments are updated?
– Krishna
6 hours ago
@Krishna You can do it withfilecontentshelp. See my updated answer.
– Ignasi
6 hours ago
@lgnasi Yes, just finished trying your combined solution with thefilecontentspackage. It works! Thank you. Upvoted and marked as accepted.
– Krishna
5 hours ago
add a comment |
@lgnasi thank you. But this does not look like a nice option.Is it possible to redefinephototo accept both LaTeX commands as well as as image file paths? If I want to update theqr codein the future, I have to remember to compile the original image. That's tedious and error-prone. At the very least can we have one single compilation that automatically updates the image whenever theqrcodecommand arguments are updated?
– Krishna
6 hours ago
@Krishna You can do it withfilecontentshelp. See my updated answer.
– Ignasi
6 hours ago
@lgnasi Yes, just finished trying your combined solution with thefilecontentspackage. It works! Thank you. Upvoted and marked as accepted.
– Krishna
5 hours ago
@lgnasi thank you. But this does not look like a nice option.Is it possible to redefine
photo to accept both LaTeX commands as well as as image file paths? If I want to update the qr code in the future, I have to remember to compile the original image. That's tedious and error-prone. At the very least can we have one single compilation that automatically updates the image whenever the qrcode command arguments are updated?– Krishna
6 hours ago
@lgnasi thank you. But this does not look like a nice option.Is it possible to redefine
photo to accept both LaTeX commands as well as as image file paths? If I want to update the qr code in the future, I have to remember to compile the original image. That's tedious and error-prone. At the very least can we have one single compilation that automatically updates the image whenever the qrcode command arguments are updated?– Krishna
6 hours ago
@Krishna You can do it with
filecontents help. See my updated answer.– Ignasi
6 hours ago
@Krishna You can do it with
filecontents help. See my updated answer.– Ignasi
6 hours ago
@lgnasi Yes, just finished trying your combined solution with the
filecontents package. It works! Thank you. Upvoted and marked as accepted.– Krishna
5 hours ago
@lgnasi Yes, just finished trying your combined solution with the
filecontents package. It works! Thank you. Upvoted and marked as accepted.– Krishna
5 hours ago
add a comment |
In the code of class moderncv, style classic you can find an if-then-else construct checking if a photo is defined (printing it) or not (doing nothing). I added inside the empty case a new if-then-else testing, if a new command qrphoto is defined. If it is defined the code prints it, in the other case it does nothing.
The new command for the qrphoto is:
NewDocumentCommand{qrphoto}{O{64pt}O{0.4pt}m}{def@qrphotowidth{#1}def@qrphotoframewidth{#2}def@qrphoto{#3}}
With this command I define the needed values @qrphotowidth etc. for later usage.
Now we can patch the original command with
patchcmd{makecvhead}%
{%
ifthenelse{isundefined{@photo}}{}%
}% code to patch
{% new code <=========================================================
ifthenelse{isundefined{@photo}}%
{%
ifthenelse{isundefined{@qrphoto}}%
{}%
{%
if@left%
hspace*{separatorcolumnwidth}fi%
color{color1}%
setlength{fboxrule}{@qrphotoframewidth}%
ifdim@qrphotoframewidth=0pt%
setlength{fboxsep}{0pt}fi%
raisebox{1cm}{framebox{qrcode[hyperlink,height=@qrphotowidth]{@qrphoto}}}
}
}%
}% end new code <=====================================================
{}% success
{fail}% failure
The command raisebox[1cm] is needed to get the qr-code on the right position (I did not search for the reason, why I need it here. The used value is okay for sizes of the resulting qr-code of 2cm (I used for the example code) or more. If your qr-code should be smaller you need to change my used value of 1cm to a lower value. You will have to try it out.
As you can see I deleted the command includegraphics. With command qrphoto qrcode... from package qrcode.
With the command
qrphoto[2cm][0.5pt]{https://tex.stackexchange.com/questions/474546/}
for example you can add an qr-code-image with a hight and width of 2cm, a frame around it with a line of 0.5pt and the content of the qr-code-image is https://tex.stackexchange.com/questions/474546/ (this question).
So with the following complete MWE
documentclass[11pt,a4paper,sans]{moderncv}
moderncvstyle{classic}
usepackage{graphicx}
usepackage{qrcode}
firstname{John}
familyname{Doe}
address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
phone[mobile]{123 456 7890}
email{someone@xyz.com}
makeatletter
NewDocumentCommand{qrphoto}{O{64pt}O{0.4pt}m}{def@qrphotowidth{#1}def@qrphotoframewidth{#2}def@qrphoto{#3}}
% to patch the code of moderncv, version 2.0.0
%usepackage{etoolbox} % already loaded in moderncv <===================
patchcmd{makecvhead}%
{%
ifthenelse{isundefined{@photo}}{}%
}% code to patch
{% new code <=========================================================
ifthenelse{isundefined{@photo}}%
{%
ifthenelse{isundefined{@qrphoto}}%
{}%
{%
if@left%
hspace*{separatorcolumnwidth}fi%
color{color1}%
setlength{fboxrule}{@qrphotoframewidth}%
ifdim@qrphotoframewidth=0pt%
setlength{fboxsep}{0pt}fi%
raisebox{1cm}{framebox{qrcode[hyperlink,height=@qrphotowidth]{@qrphoto}}}
}
}%
}% end new code <=====================================================
{}% success
{fail}% failure
makeatother
%photo[64pt][0.5pt]{example-image}
qrphoto[2cm][0.5pt]{https://tex.stackexchange.com/questions/474546/} %
begin{document}
makecvtitle
end{document}
you get the following result:

Please note that you can only print a photo or a qr-code. If you have a defined photo and qrphoto only the photo is printed!
add a comment |
In the code of class moderncv, style classic you can find an if-then-else construct checking if a photo is defined (printing it) or not (doing nothing). I added inside the empty case a new if-then-else testing, if a new command qrphoto is defined. If it is defined the code prints it, in the other case it does nothing.
The new command for the qrphoto is:
NewDocumentCommand{qrphoto}{O{64pt}O{0.4pt}m}{def@qrphotowidth{#1}def@qrphotoframewidth{#2}def@qrphoto{#3}}
With this command I define the needed values @qrphotowidth etc. for later usage.
Now we can patch the original command with
patchcmd{makecvhead}%
{%
ifthenelse{isundefined{@photo}}{}%
}% code to patch
{% new code <=========================================================
ifthenelse{isundefined{@photo}}%
{%
ifthenelse{isundefined{@qrphoto}}%
{}%
{%
if@left%
hspace*{separatorcolumnwidth}fi%
color{color1}%
setlength{fboxrule}{@qrphotoframewidth}%
ifdim@qrphotoframewidth=0pt%
setlength{fboxsep}{0pt}fi%
raisebox{1cm}{framebox{qrcode[hyperlink,height=@qrphotowidth]{@qrphoto}}}
}
}%
}% end new code <=====================================================
{}% success
{fail}% failure
The command raisebox[1cm] is needed to get the qr-code on the right position (I did not search for the reason, why I need it here. The used value is okay for sizes of the resulting qr-code of 2cm (I used for the example code) or more. If your qr-code should be smaller you need to change my used value of 1cm to a lower value. You will have to try it out.
As you can see I deleted the command includegraphics. With command qrphoto qrcode... from package qrcode.
With the command
qrphoto[2cm][0.5pt]{https://tex.stackexchange.com/questions/474546/}
for example you can add an qr-code-image with a hight and width of 2cm, a frame around it with a line of 0.5pt and the content of the qr-code-image is https://tex.stackexchange.com/questions/474546/ (this question).
So with the following complete MWE
documentclass[11pt,a4paper,sans]{moderncv}
moderncvstyle{classic}
usepackage{graphicx}
usepackage{qrcode}
firstname{John}
familyname{Doe}
address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
phone[mobile]{123 456 7890}
email{someone@xyz.com}
makeatletter
NewDocumentCommand{qrphoto}{O{64pt}O{0.4pt}m}{def@qrphotowidth{#1}def@qrphotoframewidth{#2}def@qrphoto{#3}}
% to patch the code of moderncv, version 2.0.0
%usepackage{etoolbox} % already loaded in moderncv <===================
patchcmd{makecvhead}%
{%
ifthenelse{isundefined{@photo}}{}%
}% code to patch
{% new code <=========================================================
ifthenelse{isundefined{@photo}}%
{%
ifthenelse{isundefined{@qrphoto}}%
{}%
{%
if@left%
hspace*{separatorcolumnwidth}fi%
color{color1}%
setlength{fboxrule}{@qrphotoframewidth}%
ifdim@qrphotoframewidth=0pt%
setlength{fboxsep}{0pt}fi%
raisebox{1cm}{framebox{qrcode[hyperlink,height=@qrphotowidth]{@qrphoto}}}
}
}%
}% end new code <=====================================================
{}% success
{fail}% failure
makeatother
%photo[64pt][0.5pt]{example-image}
qrphoto[2cm][0.5pt]{https://tex.stackexchange.com/questions/474546/} %
begin{document}
makecvtitle
end{document}
you get the following result:

Please note that you can only print a photo or a qr-code. If you have a defined photo and qrphoto only the photo is printed!
add a comment |
In the code of class moderncv, style classic you can find an if-then-else construct checking if a photo is defined (printing it) or not (doing nothing). I added inside the empty case a new if-then-else testing, if a new command qrphoto is defined. If it is defined the code prints it, in the other case it does nothing.
The new command for the qrphoto is:
NewDocumentCommand{qrphoto}{O{64pt}O{0.4pt}m}{def@qrphotowidth{#1}def@qrphotoframewidth{#2}def@qrphoto{#3}}
With this command I define the needed values @qrphotowidth etc. for later usage.
Now we can patch the original command with
patchcmd{makecvhead}%
{%
ifthenelse{isundefined{@photo}}{}%
}% code to patch
{% new code <=========================================================
ifthenelse{isundefined{@photo}}%
{%
ifthenelse{isundefined{@qrphoto}}%
{}%
{%
if@left%
hspace*{separatorcolumnwidth}fi%
color{color1}%
setlength{fboxrule}{@qrphotoframewidth}%
ifdim@qrphotoframewidth=0pt%
setlength{fboxsep}{0pt}fi%
raisebox{1cm}{framebox{qrcode[hyperlink,height=@qrphotowidth]{@qrphoto}}}
}
}%
}% end new code <=====================================================
{}% success
{fail}% failure
The command raisebox[1cm] is needed to get the qr-code on the right position (I did not search for the reason, why I need it here. The used value is okay for sizes of the resulting qr-code of 2cm (I used for the example code) or more. If your qr-code should be smaller you need to change my used value of 1cm to a lower value. You will have to try it out.
As you can see I deleted the command includegraphics. With command qrphoto qrcode... from package qrcode.
With the command
qrphoto[2cm][0.5pt]{https://tex.stackexchange.com/questions/474546/}
for example you can add an qr-code-image with a hight and width of 2cm, a frame around it with a line of 0.5pt and the content of the qr-code-image is https://tex.stackexchange.com/questions/474546/ (this question).
So with the following complete MWE
documentclass[11pt,a4paper,sans]{moderncv}
moderncvstyle{classic}
usepackage{graphicx}
usepackage{qrcode}
firstname{John}
familyname{Doe}
address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
phone[mobile]{123 456 7890}
email{someone@xyz.com}
makeatletter
NewDocumentCommand{qrphoto}{O{64pt}O{0.4pt}m}{def@qrphotowidth{#1}def@qrphotoframewidth{#2}def@qrphoto{#3}}
% to patch the code of moderncv, version 2.0.0
%usepackage{etoolbox} % already loaded in moderncv <===================
patchcmd{makecvhead}%
{%
ifthenelse{isundefined{@photo}}{}%
}% code to patch
{% new code <=========================================================
ifthenelse{isundefined{@photo}}%
{%
ifthenelse{isundefined{@qrphoto}}%
{}%
{%
if@left%
hspace*{separatorcolumnwidth}fi%
color{color1}%
setlength{fboxrule}{@qrphotoframewidth}%
ifdim@qrphotoframewidth=0pt%
setlength{fboxsep}{0pt}fi%
raisebox{1cm}{framebox{qrcode[hyperlink,height=@qrphotowidth]{@qrphoto}}}
}
}%
}% end new code <=====================================================
{}% success
{fail}% failure
makeatother
%photo[64pt][0.5pt]{example-image}
qrphoto[2cm][0.5pt]{https://tex.stackexchange.com/questions/474546/} %
begin{document}
makecvtitle
end{document}
you get the following result:

Please note that you can only print a photo or a qr-code. If you have a defined photo and qrphoto only the photo is printed!
In the code of class moderncv, style classic you can find an if-then-else construct checking if a photo is defined (printing it) or not (doing nothing). I added inside the empty case a new if-then-else testing, if a new command qrphoto is defined. If it is defined the code prints it, in the other case it does nothing.
The new command for the qrphoto is:
NewDocumentCommand{qrphoto}{O{64pt}O{0.4pt}m}{def@qrphotowidth{#1}def@qrphotoframewidth{#2}def@qrphoto{#3}}
With this command I define the needed values @qrphotowidth etc. for later usage.
Now we can patch the original command with
patchcmd{makecvhead}%
{%
ifthenelse{isundefined{@photo}}{}%
}% code to patch
{% new code <=========================================================
ifthenelse{isundefined{@photo}}%
{%
ifthenelse{isundefined{@qrphoto}}%
{}%
{%
if@left%
hspace*{separatorcolumnwidth}fi%
color{color1}%
setlength{fboxrule}{@qrphotoframewidth}%
ifdim@qrphotoframewidth=0pt%
setlength{fboxsep}{0pt}fi%
raisebox{1cm}{framebox{qrcode[hyperlink,height=@qrphotowidth]{@qrphoto}}}
}
}%
}% end new code <=====================================================
{}% success
{fail}% failure
The command raisebox[1cm] is needed to get the qr-code on the right position (I did not search for the reason, why I need it here. The used value is okay for sizes of the resulting qr-code of 2cm (I used for the example code) or more. If your qr-code should be smaller you need to change my used value of 1cm to a lower value. You will have to try it out.
As you can see I deleted the command includegraphics. With command qrphoto qrcode... from package qrcode.
With the command
qrphoto[2cm][0.5pt]{https://tex.stackexchange.com/questions/474546/}
for example you can add an qr-code-image with a hight and width of 2cm, a frame around it with a line of 0.5pt and the content of the qr-code-image is https://tex.stackexchange.com/questions/474546/ (this question).
So with the following complete MWE
documentclass[11pt,a4paper,sans]{moderncv}
moderncvstyle{classic}
usepackage{graphicx}
usepackage{qrcode}
firstname{John}
familyname{Doe}
address{83 Fancy Avenue}{Noweheresville}{Gotham City 24061}
phone[mobile]{123 456 7890}
email{someone@xyz.com}
makeatletter
NewDocumentCommand{qrphoto}{O{64pt}O{0.4pt}m}{def@qrphotowidth{#1}def@qrphotoframewidth{#2}def@qrphoto{#3}}
% to patch the code of moderncv, version 2.0.0
%usepackage{etoolbox} % already loaded in moderncv <===================
patchcmd{makecvhead}%
{%
ifthenelse{isundefined{@photo}}{}%
}% code to patch
{% new code <=========================================================
ifthenelse{isundefined{@photo}}%
{%
ifthenelse{isundefined{@qrphoto}}%
{}%
{%
if@left%
hspace*{separatorcolumnwidth}fi%
color{color1}%
setlength{fboxrule}{@qrphotoframewidth}%
ifdim@qrphotoframewidth=0pt%
setlength{fboxsep}{0pt}fi%
raisebox{1cm}{framebox{qrcode[hyperlink,height=@qrphotowidth]{@qrphoto}}}
}
}%
}% end new code <=====================================================
{}% success
{fail}% failure
makeatother
%photo[64pt][0.5pt]{example-image}
qrphoto[2cm][0.5pt]{https://tex.stackexchange.com/questions/474546/} %
begin{document}
makecvtitle
end{document}
you get the following result:

Please note that you can only print a photo or a qr-code. If you have a defined photo and qrphoto only the photo is printed!
answered 49 mins ago
KurtKurt
37.6k847162
37.6k847162
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%2f474546%2fhow-to-replace-photo-in-moderncv-classic-with-a-qr-code%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
Are you loading the
qrcodepackage? I don't think moderncv loads it, or at least it didn't last time I checked, which was a few years ago– Chris H
6 hours ago
@ChrisH yes, my
MWEforgot to include it. Updated themwesuitably. The errror is not due to this.– Krishna
6 hours ago
It seems that the argument of
photois a graphics file, not a LaTeX command. Have you tried to compile the qrcode to a pdf file, and to include the latter?– marmot
6 hours ago
@marmot that doesn't sound like an elegant option to me. Is it possible to redefine
phototo accept both LaTeX commands as well as as image file paths?– Krishna
6 hours ago
@marmot If I want to update the
qr codein the future, I have to remember to re-compile the qr code image. That's tedious and error-prone. At the very least can we have one single compilation that automatically updates the image whenever theqrcodecommand arguments are updated?– Krishna
6 hours ago