> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/it/formattazione/10-counters.md).

# Contatori

## Introduzione ai contatori LaTeX

La composizione tipografica basata su LaTeX è una forma specializzata di programmazione: stai usando un linguaggio di composizione tipografica (comandi LaTeX) per fornire “istruzioni” che producono un output: il documento LaTeX compilato sotto forma di file PDF. Come in qualsiasi attività di programmazione, è probabile che tu debba usare LaTeX per memorizzare temporaneamente valori interi per un uso successivo nel tuo documento (codice)—potresti voler:

* comporre nel documento questi interi memorizzati
* fornire la numerazione automatica di determinati elementi del documento
* usarli come variabili per controllare codice condizionale (o cicli)
* modificarne e aggiornarne i valori incrementandoli/decrementandoli di un valore fisso
* reimpostarli su valori completamente diversi

Tali attività di elaborazione di interi sono estremamente comuni nei linguaggi di programmazione “normali” come Javascript, C, Lua o qualsiasi altro linguaggio di tua scelta, in cui in genere dichiari (crei un nome per) una variabile (per contenere un intero) e poi le assegni un valore. Il linguaggio di composizione tipografica LaTeX offre funzionalità simili, sebbene implementate in modo piuttosto diverso, come vedremo qui sotto.

In sostanza, un contatore LaTeX è il nome di una “variabile LaTeX” usata per memorizzare valori interi che possono essere utilizzati per le attività elencate sopra, e molto altro ancora. Lo stesso LaTeX usa numerosi contatori interni che forniscono la numerazione di pagine, sezioni, tabelle, figure, elenchi puntati/numerati, ecc. Questo articolo spiega come accedere a tali contatori e modificarli e come crearne e usarne di nuovi.

## Comandi LaTeX per lavorare con i contatori

Ecco un elenco dei comandi sui contatori di LaTeX con i rispettivi rimandi alle descrizioni nelle sezioni seguenti.

Creazione e incremento dei contatori:

* [`\newcounter{somecounter}[anothercounter]`](#newcountersomecounteranothercounter)
* [`\setcounter{somecounter}{number}`](#setcountersomecounternumber)
* [`\addtocounter{somecounter}{number}`](#addtocountersomecounternumber)
* [`\stepcounter{somecounter}`](#stepcountersomecounter)
* [`\refstepcounter{somecounter}`](#refstepcountersomecounter)

Accesso e stampa dei valori dei contatori:

* [`\arabic{somecounter}`](#arabicsomecounter)
* [`\roman{somecounter}`](#romansomecounter)
* [`\Roman{somecounter}`](#romanoutput)
* [`\alph{somecounter}`](#alphsomecounter)
* [`\Alph{somecounter}`](#alphoutput)
* [`\fnsymbol{somecounter}`](#fnsymbolsomecounter)
* [`\value{somecounter}`](#valuesomecounter)

Altri comandi per i contatori:

* [`\counterwithin{somecounter}{anothercounter}`](#counterwithinsomecounteranothercounter)
* [`\counterwithout{somecounter}{anothercounter}`](#counterwithoutsomecounteranothercounter)

### Creazione e incremento dei contatori

#### \newcounter{somecounter}\[anothercounter]

Usato per definire un nuovo contatore. Il secondo argomento, racchiuso in `[]`, è facoltativo ma, se usato, definisce `*somecounter*` come un nuovo contatore che viene azzerato quando `*anothercounter*` viene incrementato. `\newcounter` viene spesso usato nella sua forma più semplice `\newcounter{*somecounter*}` che crea `*somecounter*` e lo inizializza al valore 0.

* **Nota**: Per ogni contatore creato dal `\newcounter` comando, esso *anche* definisce un comando che può essere usato per comporre il valore del contatore. Per esempio, `\newcounter{*mycounter*}` definisce un comando chiamato `\the*mycounter*`. Un esempio è mostrato nel seguente frammento di codice LaTeX, che puoi aprire in Overleaf come documento completo, usando il link fornito:

```latex
\newcounter{mycounter}
\setcounter{mycounter}{42}
Ora puoi scrivere \verb|\themycounter| per ottenere \themycounter.
```

[Apri questo frammento di LaTeX in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Using+newcounter\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cnewcounter%7Bmycounter%7D%0A%5Csetcounter%7Bmycounter%7D%7B42%7D%0AYou+can+now+write+%5Cverb%7C%5Cthemycounter%7C+to+obtain+%5Cthemycounter.%0A%5Cend%7Bdocument%7D)

Questo esempio produce $$\text{You can now write }\verb|\themycounter|\text{ to obtain 42.}$$

* **Nota**: Se `*mycounter*` è già stato definito LaTeX restituirà l'errore `c@mycounter already defined`, come dimostra il seguente esempio che puoi aprire in Overleaf.

```latex
\newcounter{mycounter}
...molto codice... ma ce ne dimentichiamo e scriviamo di nuovo \verb|\newcounter{mycounter}|
\newcounter{mycounter}
```

[Apri questo ***codice che genera l'errore*** in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Using+newcounter\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cnewcounter%7Bmycounter%7D%0A...lots+of+code...+but+we+forget+and+write+%5Cverb%7C%5Cnewcounter%7Bmycounter%7D%7C+again%0A%5Cnewcounter%7Bmycounter%7D%0A%5Cend%7Bdocument%7D)

#### \setcounter{somecounter}{number}

Imposta `*somecounter*` a contenere il valore `*number*`.

* **Nota**: `*number*` può essere positivo o negativo.

Un esempio è mostrato nel seguente frammento di codice LaTeX, che puoi aprire in Overleaf come documento completo, usando il link fornito:

```latex
\noindent Crea un nuovo contatore \texttt{myvar} e assegnagli il valore \texttt{42}.
\vspace{10pt}

\newcounter{myvar}
\setcounter{myvar}{42}

\noindent Scrivere \verb|\themymar| compone \texttt{\themyvar}.
\vspace{10pt}

\noindent Successivamente, cambieremo \texttt{myvar} in \texttt{-42}, scrivendo \verb|\setcounter{myvar}{-42}|
\setcounter{myvar}{-42}. Ora, scrivendo \verb|\themyvar| si ottiene \texttt{\themyvar}.
```

[Apri questo frammento di LaTeX in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Using+newcounter\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cnoindent+Create+a+new+counter+%5Ctexttt%7Bmyvar%7D+and+assign+it+the+value+%5Ctexttt%7B42%7D.%0A%5Cvspace%7B10pt%7D%0A%0A%5Cnewcounter%7Bmyvar%7D%0A%5Csetcounter%7Bmyvar%7D%7B42%7D+%0A%0A%5Cnoindent+Writing+%5Cverb%7C%5Cthemymar%7C+typesets+%5Ctexttt%7B%5Cthemyvar%7D.%0A%5Cvspace%7B10pt%7D%0A%0A%5Cnoindent+Next%2C+we%27ll+change+%5Ctexttt%7Bmyvar%7D+to+%5Ctexttt%7B-42%7D%2C+writing+%5Cverb%7C%5Csetcounter%7Bmyvar%7D%7B-42%7D%7C%0A%5Csetcounter%7Bmyvar%7D%7B-42%7D.+Now%2C+writing+%5Cverb%7C%5Cthemyvar%7C+outputs+%5Ctexttt%7B%5Cthemyvar%7D.%0A%5Cend%7Bdocument%7D)

#### \addtocounter{somecounter}{number}

Incrementa il contatore `*somecounter*` di un valore pari a `*number*`.

* **Nota**: `*number*` può essere positivo, per aumentare il valore del contatore, oppure negativo per diminuirlo. Per esempio:

```latex
\addtocounter{somecounter}{-1} % diminuisce somecounter di 1
```

Un esempio è mostrato nel seguente frammento di codice LaTeX, che puoi aprire in Overleaf come documento completo, usando il link fornito:

```latex
\noindent Crea un nuovo contatore \texttt{myvar} e assegnagli il valore \texttt{42}.
\vspace{10pt}

\newcounter{myvar}
\setcounter{myvar}{42}

\noindent Scrivere \verb|\themymar| compone \texttt{\themyvar}.
\vspace{10pt}

\noindent Successivamente, cambieremo \texttt{myvar} in \texttt{142} scrivendo \verb|\addtocounter{myvar}{100}|\addtocounter{myvar}{100}. Ora, scrivendo \verb|\themyvar| si ottiene \texttt{\themyvar}.
```

[Apri questo frammento di LaTeX in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Using+addtocounter\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cnoindent+Create+a+new+counter+%5Ctexttt%7Bmyvar%7D+and+assign+it+the+value+%5Ctexttt%7B42%7D.%0A%5Cvspace%7B10pt%7D%0A%0A%5Cnewcounter%7Bmyvar%7D%0A%5Csetcounter%7Bmyvar%7D%7B42%7D+%0A%0A%5Cnoindent+Writing+%5Cverb%7C%5Cthemymar%7C+typesets+%5Ctexttt%7B%5Cthemyvar%7D.%0A%5Cvspace%7B10pt%7D%0A%0A%5Cnoindent+Next%2C+we%E2%80%99ll+change+%5Ctexttt%7Bmyvar%7D+to+%5Ctexttt%7B142%7D+by+writing+%5Cverb%7C%5Caddtocounter%7Bmyvar%7D%7B100%7D%7C%5Caddtocounter%7Bmyvar%7D%7B100%7D.+Now%2C+writing+%5Cverb%7C%5Cthemyvar%7C+outputs+%5Ctexttt%7B%5Cthemyvar%7D.%0A%5Cend%7Bdocument%7D)

#### \stepcounter{somecounter}

Incrementa `*somecounter*` di 1. Un esempio è mostrato nel seguente frammento di codice LaTeX, che puoi aprire in Overleaf come documento completo, usando il link fornito:

```latex
Se creiamo un nuovo contatore scrivendo \verb|\newcounter{mycounter}|
\newcounter{mycounter} allora il contatore \texttt{mycounter} viene creato e
inizializzato a zero, come puoi vedere se scrivi \verb|\themycounter|:
\texttt{mycounter} al momento memorizza: \themycounter.

Se ora scriviamo \verb|\stepcounter{mycounter}|\stepcounter{mycounter} allora
\verb|\themycounter| ora contiene il valore \themycounter.
```

[Apri questo frammento di LaTeX in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Using+stepcounter\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0AIf+we+create+a+new+counter+by+writing+%5Cverb%7C%5Cnewcounter%7Bmycounter%7D%7C%0A%5Cnewcounter%7Bmycounter%7D+then+the+counter+%5Ctexttt%7Bmycounter%7D+is+created+and+%0Ainitialized+to+zero%2C+as+you+can+see+if+you+write+%5Cverb%7C%5Cthemycounter%7C%3A%0A%5Ctexttt%7Bmycounter%7D+currently+stores%3A+%5Cthemycounter.+%0A%0AIf+we+now+write+%5Cverb%7C%5Cstepcounter%7Bmycounter%7D%7C%5Cstepcounter%7Bmycounter%7D+then+%0A%5Cverb%7C%5Cthemycounter%7C+now+contains+the+value+%5Cthemycounter.%0A%5Cend%7Bdocument%7D)

#### \refstepcounter{somecounter}

Aumenta `*somecounter*` di 1 e lo rende visibile per il meccanismo di riferimento, impostando anche il valore in modo che tu possa usare `comando \label` in seguito.

**Esempio che usa \refstepcounter**

L'esempio seguente usa `\refstepcounter` per creare un nuovo contatore per un `esempio` ambiente e usa `comando \label` e `\ref` per illustrare i riferimenti usando la `esempio` variabile del contatore.

```latex
\documentclass{article}

\newcounter{example}[section]
\newenvironment{example}[1][]{\refstepcounter{example}\par\medskip
   \noindent\textbf{Esempio~\theexample. #1} \rmfamily}{\medskip}

\begin{document}
\section{Tre esempi}
\begin{example}
Crea un'etichetta in questo primo esempio \verb|\label{ex:1}|\label{ex:1}. Questo è il primo esempio. Il contatore \texttt{example} verrà azzerato all'inizio di ogni nuova \verb|\section| del documento.
\end{example}

\begin{example}
Ed ecco un altro esempio numerato. Crea una seconda \verb|\label{ex:2}|\label{ex:2} per fare riferimento in seguito a questo. Nell'Esempio \ref{ex:1} leggiamo... qualcosa.
\end{example}

\begin{example}
Ed ecco un altro esempio numerato: usa \verb|\theexample| per comporre il numero attualmente assegnato al contatore \texttt{example}: è  \theexample.
\end{example}

\section{Un'altra sezione}
Abbiamo appena iniziato una nuova sezione, il che significa che il contatore \texttt{example} è stato impostato a \theexample.
Faremo riferimento agli esempi della sezione precedente (Esempi \ref{ex:1} e \ref{ex:2}).  Questa è una sezione fittizia senza alcuno scopo se non contenere testo. Il contatore \texttt{section} di questa sezione può essere composto usando \verb|\thesection|: al momento gli è assegnato il valore di \thesection.

\begin{example}
Questo è il primo esempio in questa sezione: il contatore \texttt{example} è stato incrementato ed è ora impostato a \theexample.
\end{example}
\end{document}
```

[Apri questo `\refstepcounter` esempio in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=An+example+using+refstepcounter\&snip=%5Cdocumentclass%7Barticle%7D%0A%0A%5Cnewcounter%7Bexample%7D%5Bsection%5D%0A%5Cnewenvironment%7Bexample%7D%5B1%5D%5B%5D%7B%5Crefstepcounter%7Bexample%7D%5Cpar%5Cmedskip%0A+++%5Cnoindent%5Ctextbf%7BExample%7E%5Ctheexample.+%231%7D+%5Crmfamily%7D%7B%5Cmedskip%7D%0A%0A%5Cbegin%7Bdocument%7D%0A%5Csection%7BThree+examples%7D%0A%5Cbegin%7Bexample%7D%0ACreate+a+label+in+this+first+example+%5Cverb%7C%5Clabel%7Bex%3A1%7D%7C%5Clabel%7Bex%3A1%7D.+This+is+the+first+example.+The+%5Ctexttt%7Bexample%7D+counter+will+be+reset+at+the+start+of+each+new+each+document+%5Cverb%7C%5Csection%7C.%0A%5Cend%7Bexample%7D%0A%0A%5Cbegin%7Bexample%7D%0AAnd+here%27s+another+numbered+example.+Create+a+second+%5Cverb%7C%5Clabel%7Bex%3A2%7D%7C%5Clabel%7Bex%3A2%7D+to+later+reference+this+one.+In+Example+%5Cref%7Bex%3A1%7D+we+read...+something.+%0A%5Cend%7Bexample%7D%0A%0A%5Cbegin%7Bexample%7D%0AAnd+here%27s+another+numbered+example%3A+use+%5Cverb%7C%5Ctheexample%7C+to+typeset+the+number+currently+assigned+to+the+%5Ctexttt%7Bexample%7D+counter%3A+it+is++%5Ctheexample.%0A%5Cend%7Bexample%7D%0A%0A%5Csection%7BAnother+section%7D%0AWe%27ve+just+started+a+new+section+meaning+that+the++%5Ctexttt%7Bexample%7D+counter+has+been+set+to+%5Ctheexample.++%0AWe%27ll+reference+examples+from+the+previous+section+%28Examples+%5Cref%7Bex%3A1%7D+and+%5Cref%7Bex%3A2%7D%29.++This+is+a+dummy+section+with+no+purpose+whatsoever+but+to+contain+text.+The+%5Ctexttt%7Bsection%7D+counter+for+this+section+can+be+typeset+using+%5Cverb%7C%5Cthesection%7C%3A+it+is++currently+assigned+the+value+of+%5Cthesection.%0A%0A%5Cbegin%7Bexample%7D%0AThis+is+the+first+example+in+this+section%3A+the+%5Ctexttt%7Bexample%7D+counter+has+been+stepped+and+now+set+to+%5Ctheexample.+%0A%5Cend%7Bexample%7D%0A%5Cend%7Bdocument%7D)

**Riepilogo del codice**

In questo esempio, il nuovo ambiente `esempio` è definito; questo ambiente ha 3 comandi specifici per il conteggio:

* `\newcounter{example}[section]`: Crea un nuovo contatore chiamato `esempio` che verrà azzerato ogni volta che il contatore `section` viene incrementato. Puoi mettere qualsiasi altro contatore al posto di `section` oppure omettere il parametro se non vuoi che il tuo contatore venga azzerato automaticamente.
* `\refstepcounter{example}`: Incrementa il `esempio` contatore di 1 e lo rende visibile per il meccanismo di riferimento, così che tu possa usare `comando \label` in seguito.
* `\theexample`: Stampa il valore attuale del contatore `esempio`.

Per ulteriori informazioni sugli ambienti definiti dall'utente, vedi [l'articolo sulla definizione di nuovi ambienti](/latex/it/comandi/02-environments.md#defining-a-new-environment)

### Accesso e stampa dei valori dei contatori

Le discussioni seguenti si basano sulle impostazioni predefinite di LaTeX prima di qualsiasi personalizzazione applicata dai pacchetti caricati dall'utente.

#### \arabic{somecounter}

Restituisci la rappresentazione di `*somecounter*` come numeri arabi: 1, 2, 3...

#### \roman{somecounter}

Restituisci la rappresentazione di `*somecounter*` come numeri romani minuscoli: i, ii, iii...

* **Nota**: Se `*somecounter*` $$\leq$$ `0` non viene prodotto alcun output. Inoltre, convertire *estremamente* grandi valori interi in numeri romani minuscoli può richiedere molto tempo per completarsi—e produce una lunga sequenza di `m` caratteri (che rappresentano il numero `1000`).
* **SUGGERIMENTO**: Se sei interessato all'algoritmo che TeX usa per convertire i numeri arabi in numeri romani, puoi leggerne in questo articolo su [Algoritmi per i numeri romani](https://www.hanshq.net/roman-numerals.html#tex).

#### \Roman{somecounter}

Restituisci la rappresentazione di `*somecounter*` come numeri romani maiuscoli: I, II, III...

* **Nota**: Se `*somecounter*` $$\leq$$ `0` non viene prodotto alcun output. Inoltre, convertire *estremamente* grandi valori interi in numeri romani maiuscoli può richiedere molto tempo per completarsi—e produce una lunga sequenza di `M` caratteri (che rappresentano il numero `1000`).
* **SUGGERIMENTO**: Se sei interessato all'algoritmo che TeX usa per convertire i numeri arabi in numeri romani, puoi leggerne in questo articolo su [Algoritmi per i numeri romani](https://www.hanshq.net/roman-numerals.html#tex).

#### \alph{somecounter}

Restituisci la rappresentazione di `*somecounter*` come lettera minuscola dove a=1, b=2, c=3...

* **Nota**: `*somecounter*` deve essere nell'intervallo `1` $$\leq$$ `*somecounter*` $$\leq$$ `26`, altrimenti attiverà l'errore `! Errore LaTeX: contatore troppo grande.`

#### \Alph{somecounter}

Restituisci la rappresentazione di `*somecounter*` come lettera maiuscola dove A=1, B=2, C=3...

* **Nota**: `*somecounter*` deve essere nell'intervallo `1` $$\leq$$ `*somecounter*` $$\leq$$ `26`, altrimenti attiverà l'errore `! Errore LaTeX: contatore troppo grande.`

#### \fnsymbol{somecounter}

Restituisci la rappresentazione di `*somecounter*` come simbolo di nota a piè di pagina dove 1 =∗, 2 =†...

* **Nota**: `*somecounter*` deve essere nell'intervallo `1` $$\leq$$ `*somecounter*` $$\leq$$ `9`, altrimenti attiverà l'errore `! Errore LaTeX: contatore troppo grande.`

|                           |                                   |
| ------------------------- | --------------------------------- |
| Valore di `*somecounter*` | Carattere composto da `\fnsymbol` |
| 1                         | \*                                |
| 2                         | †                                 |
| 3                         | ‡                                 |
| 4                         | §                                 |
| 5                         | ¶                                 |
| 6                         | ∥                                 |
| 7                         | ∗∗                                |
| 8                         | ††                                |
| 9                         | ‡‡                                |

#### Esempio di stampa dei valori dei contatori

Il seguente esempio dimostra l'uso dei comandi `\arabic{*somecounter*}`, `\roman{*somecounter*}`, `\Roman{*somecounter*}`, `\alph{*somecounter*}`, `\Alph{*somecounter*}`, e `\fnsymbol{*somecounter*}`.

```latex
\newcounter{somecounter}
\setcounter{somecounter}{9}
\begin{itemize}
    \item \verb|\arabic{somecounter}| compone il valore \texttt{somecounter} di  \thesomecounter{} come \arabic{somecounter}
    \item \verb|\roman{somecounter}| compone il valore \texttt{somecounter} di  \thesomecounter{} come  \roman{somecounter}
    \item \verb|\Roman{somecounter}| compone il valore \texttt{somecounter} di  \thesomecounter{} come  \Roman{somecounter}
    \item \verb|\alph{somecounter}| compone il valore \texttt{somecounter} di  \thesomecounter{} come  \alph{somecounter}
   \item \verb|\Alph{somecounter}| compone il valore \texttt{somecounter} di  \thesomecounter{} come  \Alph{somecounter}
    \item \verb|\fnsymbol{somecounter}| compone il valore \texttt{somecounter} di  \thesomecounter{} come  \fnsymbol{somecounter}
\end{itemize}
```

[Apri questo frammento di LaTeX in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Converting+counter+values\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cnewcounter%7Bsomecounter%7D%0A%5Csetcounter%7Bsomecounter%7D%7B9%7D%0A%5Cbegin%7Bitemize%7D%0A++++%5Citem+%5Cverb%7C%5Carabic%7Bsomecounter%7D%7C+typesets+the+%5Ctexttt%7Bsomecounter%7D+value+of++%5Cthesomecounter%7B%7D+as+%5Carabic%7Bsomecounter%7D+%0A++++%5Citem+%5Cverb%7C%5Croman%7Bsomecounter%7D%7C+typesets+the+%5Ctexttt%7Bsomecounter%7D+value+of++%5Cthesomecounter%7B%7D+as++%5Croman%7Bsomecounter%7D%0A++++%5Citem+%5Cverb%7C%5CRoman%7Bsomecounter%7D%7C+typesets+the+%5Ctexttt%7Bsomecounter%7D+value+of++%5Cthesomecounter%7B%7D+as++%5CRoman%7Bsomecounter%7D%0A++++%5Citem+%5Cverb%7C%5Calph%7Bsomecounter%7D%7C+typesets+the+%5Ctexttt%7Bsomecounter%7D+value+of++%5Cthesomecounter%7B%7D+as++%5Calph%7Bsomecounter%7D%0A+++%5Citem+%5Cverb%7C%5CAlph%7Bsomecounter%7D%7C+typesets+the+%5Ctexttt%7Bsomecounter%7D+value+of++%5Cthesomecounter%7B%7D+as++%5CAlph%7Bsomecounter%7D%0A++++%5Citem+%5Cverb%7C%5Cfnsymbol%7Bsomecounter%7D%7C+typesets+the+%5Ctexttt%7Bsomecounter%7D+value+of++%5Cthesomecounter%7B%7D+as++%5Cfnsymbol%7Bsomecounter%7D%0A%5Cend%7Bitemize%7D%0A%5Cend%7Bdocument%7D)

Questo esempio produce il seguente output:

![Esempio di conversione dei contatori in LaTeX](/files/243e884c39df8bbf2442eb82e6a10b2ae64f7b86)

#### \value{somecounter}

Lo scopo di questo comando, come descritto nel codice sorgente di LaTeX, è “Per accedere al valore del contatore come numero TeX”: cioè, usi `\value{somecounter}` nelle situazioni in cui LaTeX si aspetta di elaborare un valore numerico.

**(Facoltative) note di approfondimento sul comando \value**

È facile pensare che il comando `\value{*somecounter*}` componga *direttamente* il valore di `*somecounter*`, ma non è così. È destinato all'uso all'interno di altri comandi per accedere al valore del contatore come numero TeX, a differenza del comando `\thesomecounter` che produce la rappresentazione stampata di `*somecounter*`.

All'interno del codice sorgente di LaTeX, `\value` è definito come:

```latex
\def\value#1{\csname c@#1\endcsname}
```

Di conseguenza, `\value{*somecounter*}` crea un'istanza della sequenza di controllo interna di LaTeX `\c@somecounter` che contiene il valore del contatore `*somecounter*`.

**Esempio**

Il seguente esempio mostra un caso d'uso basilare di `\value`.

```latex
\noindent Inizia dichiarando due nuovi contatori:
\begin{verbatim}
\newcounter{first}
\newcounter{second}
\end{verbatim}

\newcounter{first}
\newcounter{second}

\noindent Più tardi nel codice imposti i loro valori:
\begin{verbatim}
\setcounter{first}{100}
\setcounter{second}{50}
\end{verbatim}

\setcounter{first}{100}
\setcounter{second}{50}
\noindent Poi scrivi altro codice \LaTeX{}...\vspace{10pt}

\noindent A un certo punto potremmo voler aggiungere il valore del contatore \texttt{second} al contatore \texttt{first}. Un modo per farlo è usare \verb|\value| per ottenere il valore \textit{corrente} memorizzato nel contatore \texttt{second}:

\begin{verbatim}
\addtocounter{first}{\value{second}}
\end{verbatim}

\addtocounter{first}{\value{second}}\noindent Il valore di \texttt{first} può essere restituito con \verb|\thefirst|: \thefirst. Possiamo anche scrivere \verb|\the\value{first}| che compone anche \the\value{first}. Tuttavia, scrivere \verb|\value{first}| genererà l'errore \texttt{Missing number, treated as zero} perché \LaTeX{} tenta quindi di eseguire il comando interno \verb|\c@first|. Decommenta la riga seguente per generare l'errore:
\begin{verbatim}
%\value{first}
\end{verbatim}
%\value{first}
```

[Apri questo frammento di codice in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Using+the+value+command\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cnoindent+Start+by+declaring+two+new+counters%3A%0A%5Cbegin%7Bverbatim%7D%0A%5Cnewcounter%7Bfirst%7D%0A%5Cnewcounter%7Bsecond%7D++++%0A%5Cend%7Bverbatim%7D%0A%0A%5Cnewcounter%7Bfirst%7D%0A%5Cnewcounter%7Bsecond%7D%0A%0A%5Cnoindent+Sometime+later+in+your+code+you+set+their+values%3A%0A%5Cbegin%7Bverbatim%7D%0A%5Csetcounter%7Bfirst%7D%7B100%7D%0A%5Csetcounter%7Bsecond%7D%7B50%7D++++%0A%5Cend%7Bverbatim%7D%0A%0A%5Csetcounter%7Bfirst%7D%7B100%7D%0A%5Csetcounter%7Bsecond%7D%7B50%7D++%0A%5Cnoindent+Then+you+write+more+%5CLaTeX%7B%7D+code...%5Cvspace%7B10pt%7D%0A%0A%5Cnoindent+At+some+point+we+might+want+to+add+the+value+of+counter+%5Ctexttt%7Bsecond%7D+to+counter+%5Ctexttt%7Bfirst%7D.+One+way+to+do+that+is+using+%5Cverb%7C%5Cvalue%7C+to+obtain+the+%5Ctextit%7Bcurrent%7D+value+stored+in+the+%5Ctexttt%7Bsecond%7D+counter%3A%0A%0A%5Cbegin%7Bverbatim%7D%0A%5Caddtocounter%7Bfirst%7D%7B%5Cvalue%7Bsecond%7D%7D%0A%5Cend%7Bverbatim%7D%0A%0A%5Caddtocounter%7Bfirst%7D%7B%5Cvalue%7Bsecond%7D%7D%5Cnoindent+The+value+of+%5Ctexttt%7Bfirst%7D+can+be+output+by+%5Cverb%7C%5Cthefirst%7C%3A+%5Cthefirst.+We+can+also+write+%5Cverb%7C%5Cthe%5Cvalue%7Bfirst%7D%7C+which+also+typesets+%5Cthe%5Cvalue%7Bfirst%7D.+However%2C++writing+%5Cverb%7C%5Cvalue%7Bfirst%7D%7C+will+generate+the+error+%5Ctexttt%7BMissing+number%2C+treated+as+zero%7D+because+%5CLaTeX%7B%7D+then+tries+to+execute+the+internal+command+%5Cverb%7C%5Cc%40first%7C.+Uncomment+the+following+line+to+generate+the+error%3A%0A%5Cbegin%7Bverbatim%7D%0A%25%5Cvalue%7Bfirst%7D%0A%5Cend%7Bverbatim%7D%0A%25%5Cvalue%7Bfirst%7D%0A%5Cend%7Bdocument%7D)

Questo esempio produce il seguente output:

![Esempio che usa il comando \value](/files/d7cfc5494b63312867232284faa6b41984de49ce)

### Altri comandi per i contatori

Qui descriviamo i comandi `\counterwithin` e `\counterwithout` che ha origine nel pacchetto [`chngcntr` che fornisce i comandi e le funzionalità necessarie per includere file grafici esterni. L'esempio sopra carica il](https://ctan.org/pkg/chngcntr) ma che ora sono stati integrati in LaTeX stesso—vedi [LaTeX News, aprile 2018](https://www.latex-project.org/news/latex2e-news/ltnews28.pdf). Il `chngcntr` [documentazione del pacchetto](https://mirror.ox.ac.uk/sites/ctan.org/macros/latex/contrib/chngcntr/chngcntr.pdf) fa i seguenti commenti, che aiutano a capire lo scopo di questi comandi:

Attiva `\counterwithin`:

> A volte è desiderabile modificare un contatore definito da `\newcounter{<ctr>}` per farlo comportare come se fosse stato definito come `\newcounter{<ctr>}[<within>]`. Il pacchetto fornisce il comando `\counterwithin{<ctr>}{<within>}` che realizza questo.

Attiva `\counterwithout`:

> Analogamente, il comando `\counterwithout{<ctr>}{<within>}` modifica un contatore che è stato creato da `\newcounter{<ctr>}[<within>]` per farlo comportare come se fosse stato creato da `\newcounter{<ctr>}`.

In sostanza, questi due comandi forniscono un metodo per collegare (`\counterwithin`) o scollegare (`\counterwithout`) due contatori dopo che sono stati definiti.

**\counterwithin{somecounter}{anothercounter}**

Azzera `*somecounter*` a 0 ogni volta che `*anothercounter*` viene incrementato, un meccanismo che collega i due contatori. Oltre a creare un collegamento, questo comando ridefinisce ciò che viene composto da `\the*somecounter*`: invece di restituire il valore del contatore `*somecounter*` produce `<valore di anothercounter>**.**<valore di somecounter>`. La forma con asterisco (`\counterwithin*{somecounter}{anothercounter}`) non ridefinisce il formato di stampa di `*somecounter*`, come dimostra il seguente esempio—seleziona il link sotto il codice per aprirlo in Overleaf:

```latex
\documentclass{article}
\begin{document}
\section{Un breve esempio}
\newcounter{example}
\counterwithin{example}{section}
\newcounter{exampletwo}
\counterwithin*{exampletwo}{section}
\setcounter{example}{100}
\setcounter{exampletwo}{100}
\begin{itemize}
\item \verb|\theexample| compone \theexample
\item \verb|\theexampletwo| compone \theexampletwo
\end{itemize}
\end{document}
```

[Apri questo `\counterwithin` esempio in Overleaf](https://www.overleaf.com/docs?engine=\&snip_name=Example+of+starred+version+of+counterwithin\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csection%7BA+short+example%7D%0A%5Cnewcounter%7Bexample%7D%0A%5Ccounterwithin%7Bexample%7D%7Bsection%7D%0A%5Cnewcounter%7Bexampletwo%7D%0A%5Ccounterwithin%2A%7Bexampletwo%7D%7Bsection%7D%0A%5Csetcounter%7Bexample%7D%7B100%7D%0A%5Csetcounter%7Bexampletwo%7D%7B100%7D%0A%5Cbegin%7Bitemize%7D%0A%5Citem+%5Cverb%7C%5Ctheexample%7C+typesets+%5Ctheexample%0A%5Citem+%5Cverb%7C%5Ctheexampletwo%7C+typesets+%5Ctheexampletwo%0A%5Cend%7Bitemize%7D%0A%5Cend%7Bdocument%7D)

Questo esempio produce il seguente output:

![Uso del comando \counterwithin](/files/ff8ed2f6c8f31f0605604c4c84ae17ea559b2779)

Puoi usare `\counterwithin` con i contatori standard forniti da LaTeX, come:

* `section`: usato da `\section` comando
* `equation` usato dal `equation` richiede

oppure con contatori che hai creato.

**Esempio di \counterwithin e \counterwithin\***

Il seguente codice fornisce un esempio più completo dell'uso di `\counterwithin` e `\counterwithin*`; seleziona il link sotto il codice per aprirlo in Overleaf:

```latex
\documentclass{article}
\counterwithin{equation}{section}
\newcounter{example}
\counterwithin*{example}{section}
\newenvironment{example}[1][]{%
\stepcounter{example}%
\par\vspace{5pt}\noindent
\fbox{\textbf{Esempio~\thesection.\theexample}}%
\hrulefill\par\vspace{10pt}\noindent\rmfamily}%
{\par\noindent\hrulefill\vrule width10pt height2pt depth2pt\par}
\begin{document}
\section{Prima equazione}
Un testo introduttivo...
\begin{example}
\begin{equation}
    f(x)=\frac{x}{1+x^2}
\end{equation}
\end{example}

\subsection{Più dettagli}
\begin{example}
Qui discutiamo
\begin{equation}
    f(x)=\frac{x+1}{x-1}
\end{equation}
... ma non diciamo nulla
\end{example}

\subsubsection{Ancora più dettagli}
\begin{example}
\begin{equation}
    f(x)=\frac{x^2}{1+x^3}
\end{equation}
\begin{equation}
    f(x+\delta x)=\frac{(x+\delta x)^2}{1+(x+\delta x)^3}
\end{equation}
\end{example}

\section{Terza equazione}
\begin{example}
La funzione seguente...
\begin{equation}
    f_1(x)=\frac{x+1}{x-1}
\end{equation}
..è una funzione
\begin{equation}
    f_2(x)=\frac{x^2}{1+x^3}
\end{equation}
\begin{equation}
    f_3(x)=\frac{3+ x^2}{1-x^3}
\end{equation}
\end{example}
\end{document}
```

[Apri questo `\counterwithin` esempio in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+of+using+counterwithin\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Ccounterwithin%7Bequation%7D%7Bsection%7D%0A%5Cnewcounter%7Bexample%7D%0A%5Ccounterwithin%2A%7Bexample%7D%7Bsection%7D%0A%5Cnewenvironment%7Bexample%7D%5B1%5D%5B%5D%7B%25%0A%5Cstepcounter%7Bexample%7D%25%0A%5Cpar%5Cvspace%7B5pt%7D%5Cnoindent%0A%5Cfbox%7B%5Ctextbf%7BExample%7E%5Cthesection.%5Ctheexample%7D%7D%25%0A%5Chrulefill%5Cpar%5Cvspace%7B10pt%7D%5Cnoindent%5Crmfamily%7D%25%0A%7B%5Cpar%5Cnoindent%5Chrulefill%5Cvrule+width10pt+height2pt+depth2pt%5Cpar%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csection%7BFirst+equation%7D%0ASome+introductory+text...%0A%5Cbegin%7Bexample%7D%0A%5Cbegin%7Bequation%7D%0A++++f%28x%29%3D%5Cfrac%7Bx%7D%7B1%2Bx%5E2%7D%0A%5Cend%7Bequation%7D%0A%5Cend%7Bexample%7D%0A%0A%5Csubsection%7BMore+detail%7D%0A%5Cbegin%7Bexample%7D%0AHere+we+discuss%0A%5Cbegin%7Bequation%7D%0A++++f%28x%29%3D%5Cfrac%7Bx%2B1%7D%7Bx-1%7D%0A%5Cend%7Bequation%7D%0A...+but+don%27t+say+anything%0A%5Cend%7Bexample%7D%0A%0A%5Csubsubsection%7BEven+more+detail%7D%0A%5Cbegin%7Bexample%7D%0A%5Cbegin%7Bequation%7D%0A++++f%28x%29%3D%5Cfrac%7Bx%5E2%7D%7B1%2Bx%5E3%7D%0A%5Cend%7Bequation%7D%0A%5Cbegin%7Bequation%7D%0A++++f%28x%2B%5Cdelta+x%29%3D%5Cfrac%7B%28x%2B%5Cdelta+x%29%5E2%7D%7B1%2B%28x%2B%5Cdelta+x%29%5E3%7D%0A%5Cend%7Bequation%7D%0A%5Cend%7Bexample%7D%0A%0A%5Csection%7BThird+equation%7D%0A%5Cbegin%7Bexample%7D%0AThe+following+function...%0A%5Cbegin%7Bequation%7D%0A++++f_1%28x%29%3D%5Cfrac%7Bx%2B1%7D%7Bx-1%7D%0A%5Cend%7Bequation%7D%0A..is+a+function%0A%5Cbegin%7Bequation%7D%0A++++f_2%28x%29%3D%5Cfrac%7Bx%5E2%7D%7B1%2Bx%5E3%7D%0A%5Cend%7Bequation%7D%0A%5Cbegin%7Bequation%7D%0A++++f_3%28x%29%3D%5Cfrac%7B3%2B+x%5E2%7D%7B1-x%5E3%7D%0A%5Cend%7Bequation%7D%0A%5Cend%7Bexample%7D%0A%5Cend%7Bdocument%7D)

Questo esempio produce il seguente output:

![Uso del comando \counterwithin](/files/795faa4ac83bb7f6067cbee7484c8536d98ffd14)

**Riepilogo del codice**

* `\newcounter{example}`: Questo crea un nuovo contatore da usare nel nostro ambiente, anch'esso chiamato `esempio`
* `\counterwithin*{example}{section}`: Questo collega il nostro `esempio` contatore con il `section` contatore usato all'interno del `\section` comando: ogni volta che emettiamo un `\section` comando il `esempio` contatore viene azzerato a zero. Nota che abbiamo usato la versione con asterisco `\counterwithin*` per evitare la ridefinizione di `\theexample`
* Successivamente, creiamo un nuovo ambiente chiamato anch'esso `esempio`. All'interno di quell'ambiente usiamo `\stepcounter{example}` per incrementare il contatore dell'ambiente. Nota anche che scriviamo `\textbf{Example~\thesection.\theexample}` per restituire **Esempio** `<numero di sezione>.<numero di esempio>`

```latex
\newenvironment{example}[1][]{%
\stepcounter{example}%
\par\vspace{5pt}\noindent
\fbox{\textbf{Esempio~\thesection.\theexample}}%
\hrulefill\par\vspace{10pt}\noindent\rmfamily}%
{\par\noindent\hrulefill\vrule width10pt height2pt depth2pt}
```

**\counterwithout{somecounter}{anothercounter}**

`\counterwithout{*somecounter*}{*anothercounter*}` rimuove il collegamento tra `*somecounter*` e `*anothercounter*` in modo che siano indipendenti. Per qualsiasi coppia di contatori, puoi passare dall'uso di `\counterwithout` e `\counterwithin`, come mostra il seguente esempio per i `esempio` e `section` contatori—puoi aprire questo esempio in Overleaf usando il link fornito sotto il codice.

```latex
\section{Prima equazione}
\begin{example}
\begin{equation}
    f(x)=\frac{x}{1+x^2}
\end{equation}
\end{example}

\subsection{Seconda equazione}
\begin{example}
\begin{equation}
    f(x)=\frac{x+1}{x-1}
\end{equation}
\end{example}
\vspace{6pt}\noindent Nota come il contatore \texttt{example} venga reimpostato all'inizio della Sezione \ref{sec:n0}.
\section{Terza equazione}
\label{sec:n0}
\begin{example}
\begin{equation}
    f(x)=\frac{x+1}{x-1}
\end{equation}
\end{example}
\vspace{6pt}\noindent Qui abbiamo scritto \verb|\counterwithout{example}{section}| in modo che \texttt{example} non venga più reimpostato all'inizio di una sezione. Nelle Sezioni \ref{sec:n1} e \ref{sec:n2} il contatore \texttt{example} continua ad aumentare. \counterwithout{example}{section}
\section{Quarta equazione}
\label{sec:n1}
\begin{example}
\begin{equation}
    f(x)=\frac{x^2+x^3}{1+x^3}
\end{equation}
\end{example}
\section{Quinta equazione}
\label{sec:n2}
\begin{example}
\begin{equation}
    f(x,k)=\frac{x^2-x^k}{1+x^3}
\end{equation}
\end{example}
```

[Apri questo `\counterwithout` esempio in Overleaf](<https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+of+using+counterwithout\&snip=\documentclass{article}&#xA;\counterwithin{equation}{section}&#xA;\newcounter{example}&#xA;\counterwithin*{example}{section}&#xA;\newenvironment{example}\[1]\[]{%&#xA;\stepcounter{example}%&#xA;\par\vspace{3pt}\noindent&#xA;\fbox{\textbf{Example~\thesection.\theexample}}%&#xA;\hrulefill\par\vspace{3pt}\noindent\rmfamily}%&#xA;{\par\noindent\hrulefill\vrule+width10pt+height2pt+depth2pt\par}&#xA;\begin{document}&#xA;\section{First+equation}&#xA;\begin{example}&#xA;\begin{equation}&#xA;++++f(x)=\frac{x}{1+x^2}&#xA;\end{equation}&#xA;\end{example}&#xA;&#xA;\subsection{Second+equation}&#xA;\begin{example}&#xA;\begin{equation}&#xA;++++f(x)=\frac{x+1}{x-1}&#xA;\end{equation}&#xA;\end{example}&#xA;\vspace{6pt}\noindent+Note+how+the+\texttt{example}+counter+is+reset+at+the+start+Section+\ref{sec:n0}.+&#xA;\section{Third+equation}&#xA;\label{sec:n0}&#xA;\begin{example}&#xA;\begin{equation}&#xA;++++f(x)=\frac{x+1}{x-1}&#xA;\end{equation}&#xA;\end{example}&#xA;\vspace{6pt}\noindent+Here,+we+wrote+\verb|\counterwithout{example}{section}|+so+that+\texttt{example}+is+no+longer+reset+at+the+start+of+a+section.+In+Sections+\ref{sec:n1}+and+\ref{sec:n2}+the+\texttt{example}+counter+keeps+increasing.+\counterwithout{example}{section}&#xA;\section{Fourth+equation}&#xA;\label{sec:n1}&#xA;\begin{example}&#xA;\begin{equation}&#xA;++++f(x)=\frac{x^2+x^3}{1+x^3}&#xA;\end{equation}&#xA;\end{example}&#xA;\section{Fifth+equation}&#xA;\label{sec:n2}&#xA;\begin{example}&#xA;\begin{equation}&#xA;++++f(x,k)=\frac{x^2-x^k}{1+x^3}&#xA;\end{equation}&#xA;\end{example}&#xA;\end{document}>)

Questo esempio produce il seguente output:

![Uso del comando counterwithout](/files/78a7161ce7b24923687950ee5ff44cbf7e7397ae)

## Esempio

### enumerate

Il `enumerate` l'ambiente list utilizza quattro *contatore* variabili che tengono traccia del valore corrente dell'etichetta per ciascun livello:

|             |                                     |
| ----------- | ----------------------------------- |
| **Livello** | **`enumerate`** variabile contatore |
| Livello 1   | `enumi`                             |
| Livello 2   | `enumii`                            |
| Livello 3   | `enumiii`                           |
| Livello 4   | `enumiv`                            |

Questi contatori possono essere modificati usando il `\setcounter` comando. Vedi l'esempio qui sotto—che non è necessariamente la soluzione migliore (vedi l' [articolo sulle liste di Overleaf](/latex/it/concetti-di-base-di-latex/04-lists.md) per maggiori informazioni):

```latex
Questo esempio mostra un modo per modificare la numerazione di un elenco; qui, modificando il valore del contatore \texttt{enumi} per iniziare la numerazione dell'elenco a 4 (viene incrementato dal comando \verb|\item|):

\begin{enumerate}
\setcounter{enumi}{3}
\item Qualcosa.
\item Qualcos'altro.
\item Un altro elemento.
\item L'ultimo elemento dell'elenco.
\end{enumerate}
```

[Apri questo esempio in Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Modifying+an+enumerate+counter\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csection%7BIntroduction%7D%0AThis+example+shows+one+way+to+change+the+numbering+of+a+list%3B+here%2C+changing+the+value+of+the+%5Ctexttt%7Benumi%7D+counter+to+start+the+list+numbering+at+4+%28it+is+incremented+by+the+%5Cverb%7C%5Citem%7C+command%29%3A%0A%0A%5Cbegin%7Benumerate%7D%0A%5Csetcounter%7Benumi%7D%7B3%7D%0A%5Citem+Something.%0A%5Citem+Something+else.%0A%5Citem+Another+element.%0A%5Citem+The+last+item+in+the+list.%0A%5Cend%7Benumerate%7D%0A%5Cend%7Bdocument%7D)

Questo esempio produce il seguente output:

![Modifica di un contatore dell'enumerazione](/files/5e08e416424507827c000c231be7956b2546fbc0)

## Contatori predefiniti in LaTeX

| Uso                            | Nome                                                                                                                  |
| ------------------------------ | --------------------------------------------------------------------------------------------------------------------- |
| Per la struttura del documento | <p>- part<br>- chapter<br>- section<br>- subsection<br>- subsubsection<br>- paragraph<br>- subparagraph<br>- page</p> |
| Per gli ambienti flottanti     | <p>- equation<br>- figure<br>- table</p>                                                                              |
| Per le note a piè di pagina    | <p>- footnote<br>- mpfootnote</p>                                                                                     |
| Per il `enumerate` richiede    | <p>- enumi<br>- enumii<br>- enumiii<br>- enumiv</p>                                                                   |

## Approfondimenti

Per ulteriori informazioni vedi:

* [Ambienti](/latex/it/comandi/02-environments.md)
* [Comandi](/latex/it/comandi/01-commands.md)
* [Elenchi](/latex/it/concetti-di-base-di-latex/04-lists.md)
* [Numerazione delle pagine](/latex/it/formattazione/03-page-numbering.md)
* [Sezioni e capitoli](/latex/it/struttura-del-documento/01-sections-and-chapters.md)
* [Espressioni matematiche](/latex/it/matematica/01-mathematical-expressions.md)
* [Inserimento di immagini](/latex/it/altri-argomenti/27-inserting-images.md)
* [Tabelle](/latex/it/figure-e-tabelle/01-tables.md)
* [Sostenere esami in LaTeX](/latex/it/specifico-per-argomento/09-typesetting-exams-in-latex.md)
* [Scrivere il proprio pacchetto](/latex/it/file-di-classe/03-writing-your-own-package.md)
* [Scrivere la propria classe](/latex/it/file-di-classe/04-writing-your-own-class.md)
* [L'introduzione non proprio breve a LaTeX2ε](http://www.ctan.org/tex-archive/info/lshort/)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/it/formattazione/10-counters.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
