创建一个输出相同标记但略有改动的命令

创建一个输出相同标记但略有改动的命令

我需要在我的文档中多次插入以下标记:

\documentclass[a4paper]{book}

\usepackage[italian]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{fullpage}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{hyperref}
\usepackage{fancyhdr}
\usepackage{tcolorbox}

\makeatletter
\renewcommand{\@chapapp}{Lezione}
\makeatother

\definecolor{bggray}{HTML}{D3D3D3}
\definecolor{mygray}{HTML}{3E3E3E}
\definecolor{fucsia}{HTML}{F92672}
\definecolor{lightblue}{HTML}{2E6B70}
\definecolor{aquamarine}{HTML}{60B6BC}

\hypersetup{
    colorlinks=true,
    linkcolor=black,
    urlcolor=aquamarine
}
\lstset{    
    language=Java,
    backgroundcolor=\color{bggray},
    basicstyle=\footnotesize\ttfamily,
    numbers=left,
    keywordstyle=\bfseries\color{lightblue},
    commentstyle=\itshape\color{purple},
    tabsize=2,
    frame=single,
    framerule=0pt,
    framesep=8pt,    
    xleftmargin=25pt,
    xrightmargin=25pt,
    numberstyle=\tiny\color{mygray},
    %identifierstyle=\color{lightblue},
    stringstyle=\color{orange}
}

\newtcbox{\mybox}{nobeforeafter,colframe=bggray,colback=bggray,boxrule=0.5pt,arc=4pt,
  boxsep=0pt,left=6pt,right=6pt,top=6pt,bottom=6pt,tcbox raise base}
\newtcbox{\myinsidebox}{nobeforeafter,colframe=lightblue,colback=lightblue,boxrule=0.5pt,arc=4pt,
  boxsep=0pt,left=6pt,right=6pt,top=6pt,bottom=6pt,tcbox raise base}

\author{haunted85}
\title{Esercizi svolti per il corso di\\\Huge Linguaggi di Programmazione II}
\date{\small Ultimo aggiornamento: \today}

\begin{document}
\maketitle
\thispagestyle{empty}
\tableofcontents
\thispagestyle{empty}
\chapter{Assegnabilità, conversioni e sottotipi}
\section{Conversioni implicite}
Java prevede i seguenti tipi di dato:
\begin{itemize}
    \item tipi base (o primitivi): void, boolean, int, char, float, double, short, byte;
    \item riferimenti ad oggetti;
    \item array;
    \item tipo nullo.
\end{itemize}

% SNIPPET TO BE REPEATED
\mybox{\hspace{6pt}\raisebox{-4pt}{\includegraphics[scale=.30,keepaspectratio=true]{img/save_32.png}}\hspace{10pt}\myinsidebox{\color{white}{I file \texttt{.java} relativi alla lezione possono essere scaricati} \href{http://www.mediafire.com/download/559wi1sffn10pz4/lezione1_20130307.rar}{cliccando qua}.}}
\subsection{Esercizio 4 del 30 gennaio 2008}
Il codice sorgente Java compila, fornendo la seguente classe \texttt{B}:

\begin{lstlisting}
public class B {
    public static int x;

    public B() {}
    public static A copia(B b) { return new A(); }
    public static B copia (int n) { return new B(); }
    public int g() { return 0; }

}
\end{lstlisting}

\end{document}

我每次唯一需要更改的是链接。我想知道是否可以创建一个新命令,接受 URL 作为参数并输出代码片段中的标记,这样我就不必一遍又一遍地输入它了。

答案1

像这样的宏应该可以解决问题:

\newcommand{\mymessage}[1]{%
    \mybox{\hspace{6pt}\raisebox{-4pt}%
    {\includegraphics[scale=.30,keepaspectratio=true]{img/save_32.png}}\hspace{10pt}%
    \myinsidebox{\color{white}%
    {I file \texttt{.java} relativi alla lezione possono essere scaricati}%
    \href{#1}{cliccando qua}.}}}

它可以被这样调用:

\mymessage{http://mybrilliantlink.com/download/123456}

相关内容