带有URL的Latex命令



我在向Linkedin命令添加URL时遇到问题。我希望它基本上打印Linkedin徽标,我希望被明确看到的文本,以及用户点击后将重定向到的URL。下面是当前的.cls文件。

.cls文件:

newcommand{linkedinsymbol}{faLinkedin}
newcommand{printinfo}[2]{mbox{textcolor{accent}{normalfont #1}hspace{0.5em}#2hspace{2em}}}
usepackage{hyperref}
newcommand{linkedin}[1]{printinfo{linkedinsymbol}{#1}}

我试着把最后一行变成如下:

newcommand{linkedin}[2]{printinfo{linkedinsymbol}{#1}}{url{#2}}

然而,在这样做的时候,我得到了以下错误:


! LaTeX Error: Missing begin{document}.
See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...
l.91 ...{printinfo{linkedinsymbol}{#1}}{url{#2}
}
?
! Undefined control sequence.
hyper@linkurl ...tionraw >>}relax Hy@colorlink
@urlcolor #1Hy@xspace@en...
l.91 ...{printinfo{linkedinsymbol}{#1}}{url{#2}
}
?
! Undefined control sequence.
close@pdflink ->Hy@endcolorlink
Hy@VerboseLinkStop pdfendlink
l.91 ...{printinfo{linkedinsymbol}{#1}}{url{#2}
}
?

最小再现性示例:

main.tex:

PassOptionsToPackage{dvipsnames}{xcolor}
documentclass[10pt,letterpaper]{altacv}
geometry{left=1cm,right=9cm,marginparwidth=6.8cm,marginparsep=1.2cm,top=1.25cm,bottom=1.25cm,footskip=2baselineskip}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage[default]{lato}
usepackage[hidelinks]{hyperref}
begin{document}
linkedin{linkedin.com/in/varunjain-me}{www.linkedin.com/in/varunjain-me}
end{document}

.cls文件:

NeedsTeXFormat{LaTeX2e}[1995/12/01]
@ifl@t@rfmtversion{2018/04/01}{UseRawInputEncoding}{}
ProvidesClass{altacv}[2018/07/27 AltaCV v1.1.4, yet another alternative class for a résumé/curriculum vitae.]
newifif@academicons
DeclareOption{academicons}{@academiconstrue}
newifif@normalphoto
DeclareOption{normalphoto}{@normalphototrue}
DeclareOption*{PassOptionsToClass{CurrentOption}{extarticle}}
ProcessOptionsrelax
LoadClass{extarticle}
RequirePackage[margin=2cm]{geometry}
RequirePackage{fontawesome}
if@academicons
ExplSyntaxOn
msg_redirect_name:nnn { fontspec } { font-not-found } { none }
ExplSyntaxOff
RequirePackage{academicons}
newfontfamily{AI}{academicons.ttf}
fi
RequirePackage{xcolor}
colorlet{accent}{blue!70!black}
colorlet{heading}{black}
colorlet{emphasis}{black}
colorlet{body}{black!80!white}
newcommand{itemmarker}{{smalltextbullet}}
newcommand{ratingmarker}{faCircle}
RequirePackage{tikz}
usetikzlibrary{arrows}
RequirePackage[skins]{tcolorbox}
RequirePackage{enumitem}
setlist{leftmargin=*,labelsep=0.5em,nosep,itemsep=0.25baselineskip,after=vskip0.25baselineskip}
setlist[itemize]{label=itemmarker}
RequirePackage{graphicx}
RequirePackage{etoolbox}
RequirePackage{dashrule}
RequirePackage{multirow,tabularx}
RequirePackage{changepage}
setlength{parindent}{0pt}
newcommand{divider}{textcolor{body!30}{hdashrule{linewidth}{0.6pt}{0.5ex}}medskip}
newenvironment{fullwidth}{%
begin{adjustwidth}{}{dimexpr-marginparwidth-marginparseprelax}}
{end{adjustwidth}}
newcommand{linkedinsymbol}{faLinkedin}
newcommand{printinfo}[2]{mbox{textcolor{accent}{normalfont #1}hspace{0.5em}#2hspace{2em}}}
newcommand{linkedin}[2]{printinfo{linkedinsymbol}{#1}}{url{#2}}

以下是最终适用于我的场景的代码:

documentclass{article}
usepackage{fontawesome}
usepackage{xcolor}
usepackage{hyperref}
colorlet{accent}{blue!70!black}
begin{document}
newcommand{linkedinsymbol}{faLinkedin}
% newcommand{printinfo}[2]{mbox{textcolor{accent}{normalfont #1}hspace{0.5em}#2hspace{2em}}}
newcommand{weblinks}[3]{mbox{textcolor{accent}{normalfont #1}hspace{0.5em}{href{#2}{#3}}hspace{2em}}}
% newcommand{linkedin}[2]{printinfo{linkedinsymbol}{#1}{url{#2}}}
newcommand{linkedin}[2]{weblinks{linkedinsymbol}{#1}{#2}}
linkedin{http://linkedin.com/in/varunjain-me}{linkedin.com/in/varunjain}
end{document}

这个最小的例子适用于我:

documentclass{article}
usepackage{fontawesome}
usepackage{xcolor}
usepackage{hyperref}
colorlet{accent}{blue!70!black}
begin{document}
newcommand{linkedinsymbol}{faLinkedin}
newcommand{printinfo}[2]{mbox{textcolor{accent}{normalfont #1}hspace{0.5em}#2hspace{2em}}}
newcommand{linkedin}[2]{printinfo{linkedinsymbol}{#1}{url{#2}}}
linkedin{linkedin.com/in/varunjain-me}{www.linkedin.com/in/varunjain-me}
end{document}

至少它产生了一些输出。。。我不知道你到底期待什么,但你可以从这里开始。

相关内容

  • 没有找到相关文章

最新更新