0

I need to insert the following markup multiple times in my document:

\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}

the only thing I have to change everytime is the link. I am wondering if it is possible to create a new command that accepts the url as a parameter and outputs the markup in the snippet so that I don't have to type it over and over.

4
  • Can you add a minimum working example that includes a working snippet of the code you want to repeat?
    – cslstr
    Mar 9, 2014 at 17:55
  • @cslstr added MWE, I hope it is enough!
    – haunted85
    Mar 9, 2014 at 18:02
  • 1
    A MWE is a full document.
    – marczellm
    Mar 9, 2014 at 18:08
  • The MWE should begin with \documentclass and end with \end{document}. All the packages you need to get it to work should be included! But ... the minimum part means that only the elements needed should be included. lstlistings are irrelevant in this case.
    – cslstr
    Mar 9, 2014 at 18:13

1 Answer 1

1

A macro such as this should do the trick:

\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}.}}}

It would be called like this:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .