### Minimal biblatex Setup Source: https://www.overleaf.com/learn/latex/Basic_bibliography_management A minimal working example demonstrating the basic setup for the biblatex package. It includes importing the package, adding a bibliography resource, and printing the bibliography. ```latex \documentclass[letterpaper,10pt]{article} \usepackage{biblatex} %Imports biblatex package \addbibresource{sample.bib} %Import the bibliography file \begin{document} Let's cite! Einstein's journal paper \cite{einstein} and Dirac's book \cite{dirac} are physics-related items. \printbibliography %Prints bibliography \end{document} ``` -------------------------------- ### Basic Natbib Setup and Citation Source: https://www.overleaf.com/learn/latex/Natbib_citation_styles This example demonstrates the basic setup of the natbib package, including setting the bibliography style and citation style. It shows how to use \cite and \citep commands with optional arguments for pre- and post-notes. ```latex \documentclass{article} \usepackage[utf8]{inputenc} \usepackage[english]{babel} %Import the natbib package and sets a bibliography and citation styles \usepackage{natbib} \bibliographystyle{abbrvnat} \setcitestyle{authoryear,open={((},close={))}} %Citation-related commands \title{Natbib Example} \author{Overleaf team} \begin{document} \maketitle \section{First Section} This document is an example with two cited items: \textit{The \LaTeX\ Companion} book \cite[see][chap 2]{latexcompanion} and Einstein's journal paper \citep{einstein}. %Imports the bibliography file "sample.bib" \bibliography{sample} \end{document} ``` -------------------------------- ### Basic natbib setup and citation Source: https://www.overleaf.com/learn/latex/Bibliography_management_with_natbib Imports the natbib package and sets the bibliography style to unsrtnat. Includes example citations and bibliography import. ```latex \usepackage{natbib} \bibliographystyle{unsrtnat} \title{Bibliography management: \texttt{natbib} package} \author{Overleaf} \date {April 2021} \begin{document} \maketitle This document is an example of \texttt{natbib} package using in bibliography management. Three items are cited: \textit{The \LaTeX\ Companion} book \cite{latexcompanion}, the Einstein journal paper \cite{einstein}, and the Donald Knuth's website \cite{knuthwebsite}. The \LaTeX\ related items are \cite{latexcompanion,knuthwebsite}. \medskip \bibliography{sample} \end{document} ``` -------------------------------- ### Basic LaTeX Index Creation Source: https://www.overleaf.com/learn/latex/Indices This example demonstrates the fundamental setup for creating an index in a LaTeX document. It includes necessary package loading, index generation command, and printing the index. ```latex \documentclass{article} \usepackage[T1]{fontenc} \usepackage{imakeidx} \makeindex \begin{document} \section{Introduction} In this example, several keywords\index{keywords} will be used which are important and deserve to appear in the Index\index{Index}. Terms like generate\index{generate} and some\index{others} will also show up. \printindex \end{document} ``` ```latex \usepackage{imakeidx} ``` -------------------------------- ### LaTeX Example Environment with Refstepcounter Source: https://www.overleaf.com/learn/latex/Counters Defines a custom 'example' environment that uses \refstepcounter to increment a counter, making it available for \label and \ref. The counter is reset at the start of each new section. ```latex \documentclass{article} \newcounter{example}[section] \newenvironment{example}[1][]{\refstepcounter{example}\par\medskip \noindent\textbf{Example~\theexample. #1} \rmfamily}{\medskip} \begin{document} \section{Three examples} \begin{example} Create a label in this first example \verb|\label{ex:1}|\label{ex:1}. This is the first example. The \texttt{example} counter will be reset at the start of each new each document \verb|\section|. \end{example} \begin{example} And here's another numbered example. Create a second \verb|\label{ex:2}|\label{ex:2} to later reference this one. In Example \ref{ex:1} we read... something. \end{example} \begin{example} And here's another numbered example: use \verb|\theexample| to typeset the number currently assigned to the \texttt{example} counter: it is \theexample. \end{example} \section{Another section} We've just started a new section meaning that the \texttt{example} counter has been set to \theexample. We'll reference examples from the previous section (Examples \ref{ex:1} and \ref{ex:2}). This is a dummy section with no purpose whatsoever but to contain text. The \texttt{section} counter for this section can be typeset using \verb|\thesection|: it is currently assigned the value of \thesection. \begin{example} This is the first example in this section: the \texttt{example} counter has been stepped and now set to \theexample. \end{example} \end{document} ``` -------------------------------- ### Define and Use Custom Example Counter with `\counterwithin*` Source: https://www.overleaf.com/learn/latex/Counters%23Introduction_to_LaTeX_counters This example defines a custom `example` environment that is automatically numbered within sections using `\counterwithin*`. It shows how to increment the counter and display it along with the section number. ```latex \documentclass{article} \counterwithin{equation}{section} \newcounter{example} \counterwithin*{example}{section} \newenvironment{example}[1][]{% \stepcounter{example}% \par\vspace{5pt}\noindent \fbox{\textbf{Example~\thesection.\theexample}}% \hrulefill\par\vspace{10pt}\noindent\rmfamily}% {\par\noindent\hrulefill\vrule width10pt height2pt depth2pt\par} \begin{document} \section{First equation} Some introductory text... \begin{example} \begin{equation} f(x)=\frac{x}{1+x^2} \end{equation} \end{example} \subsection{More detail} \begin{example} Here we discuss \begin{equation} f(x)=\frac{x+1}{x-1} \end{equation} ... but don't say anything \end{example} \subsubsection{Even more detail} \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{Third equation} \begin{example} The following function... \begin{equation} f_1(x)=\frac{x+1}{x-1} \end{equation} ..is a function \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} ``` -------------------------------- ### Example \hbox with Horizontal Glue Source: https://www.overleaf.com/learn/latex/Articles/How_TeX_Calculates_Glue_Settings_in_an_%5Chbox Demonstrates the use of \hskip with varying stretch and shrink components within an \hbox. This setup is used to illustrate how TeX calculates the final space between elements. ```tex \hbox to100pt{\n A\hskip4pt plus3pt minus 2pt%\n B\hskip 0pt plus 2fil% \n C\hskip 0pt plus 2fill%\n D\hskip 0pt plus 3fill%\n} ``` -------------------------------- ### Example pTeX Document with latexmkrc Source: https://www.overleaf.com/learn/latex/Latex-questions/Does_Overleaf_support_pTeX%3F This snippet shows a complete Overleaf project setup including the main LaTeX file and the `latexmkrc` configuration for pTeX. ```latex \documentclass{jsarticle} \bibliographystyle{jplain} \title{p\LaTeX\ 実験} \author{林蓮枝} \begin{document} \maketitle \begin{abstract} 本稿では、文書組版システムp\LaTeX{}の使い方を解説します。p\LaTeX{}を利用するときには、あらかじめ文章中に\TeX{}コマンドと呼ばれる組版用の指示を混在させ\ldots \end{abstract} \section{導入} こんにちは世界! \end{document} ``` ```bash $latex = 'platex'; $bibtex = 'pbibtex'; $dvipdf = 'dvipdfmx %O -o %D %S'; ``` -------------------------------- ### LaTeX Example with Itemized List Source: https://www.overleaf.com/learn/latex/Commands%23Defining_a_new_command Illustrates how to create a bulleted list in LaTeX using the itemize environment and the \item command, with an example of customizing list markers. ```latex \documentclass{article} \begin{document} A list example: \begin{itemize} \item[\S] First item \item Second item \end{itemize} \end{document} ``` -------------------------------- ### Basic Math Mode Spacing Example Source: https://www.overleaf.com/learn/latex/Spacing_in_math_mode Demonstrates the basic structure for using math mode in LaTeX. This example shows how to define sets with mathematical notation. ```latex \documentclass{article} \usepackage{amssymb} \begin{document} Assume we have the next sets \[ S = \{ z \in \mathbb{C}\, |\, |z| < 1 \} \quad \textrm{and} \quad S_2=\partial{S} \] \end{document} ``` -------------------------------- ### Full Set of Text Formatting Examples in LaTeX Source: https://www.overleaf.com/learn/latex/Bold%2C_italics_and_underlining A collection of various text formatting examples including bold, italics, underline, and emphasis, demonstrating their usage and nesting. ```latex First example, bold, italics and underline: Some of the \\textbf{greatest} discoveries in \\underline{science} were made by \\textbf{\\\\emph{accidentப்பட்டன}}. \\vspace{1.5cm} Example of italicized text: Some of the greatest discoveries in science were made by \\emph{accident}. \\vspace{1.5cm} Example of boldface text: Some of the \\textbf{greatest} discoveries in science were made by accident. \\vspace{1.5cm} Example of underlined text: Some of the greatest discoveries in \\underline{science} were made by accident. \\vspace{1.5cm} Example of emphasized text in different contexts: Some of the greatest \\emph{discoveries} in science were made by accident. \\textit{Some of the greatest \\emph{discoveries} in science were made by accident.} \\textbf{Some of the greatest \\emph{discoveries} in science were made by accident.} ``` -------------------------------- ### Define and Use an Example Environment with Referencing Source: https://www.overleaf.com/learn/latex/Counters%23Introduction_to_LaTeX_counters Illustrates creating a custom environment 'example' that uses \refstepcounter to increment a counter and enable \label and \ref for cross-referencing. The counter resets with each new section. ```latex \documentclass{article} \newcounter{example}[section] \newenvironment{example}[1][] {\refstepcounter{example}\par\medskip \noindent\textbf{Example~\theexample. #1} \rmfamily}{\medskip} \begin{document} \section{Three examples} \begin{example} Create a label in this first example \verb|\label{ex:1}|\label{ex:1}. This is the first example. The \texttt{example} counter will be reset at the start of each new each document \verb|\section|. \end{example} \begin{example} And here's another numbered example. Create a second \verb|\label{ex:2}|\label{ex:2} to later reference this one. In Example \ref{ex:1} we read... something. \end{example} \begin{example} And here's another numbered example: use \verb|\theexample| to typeset the number currently assigned to the \texttt{example} counter: it is \theexample. \end{example} \section{Another section} We've just started a new section meaning that the \texttt{example} counter has been set to \theexample. We'll reference examples from the previous section (Examples \ref{ex:1} and \ref{ex:2}). This is a dummy section with no purpose whatsoever but to contain text. The \texttt{section} counter for this section can be typeset using \verb|\thesection|: it is currently assigned the value of \thesection. \begin{example} This is the first example in this section: the \texttt{example} counter has been stepped and now set to \theexample. \end{example} \end{document} ``` -------------------------------- ### Defining a Custom Environment with Nested Counters Source: https://www.overleaf.com/learn/latex/Counters%23Accessing_and_printing_counter_values Defines a custom 'example' environment that increments a counter and displays it along with the section number. This setup is useful for creating custom-numbered examples within document sections. ```latex \newenvironment{example}[1][]{% \stepcounter{example}% \par\vspace{5pt}\noindent \fbox{\textbf{Example~\thesection.\theexample}}% \hrulefill\par\vspace{10pt}\noindent\rmfamily}% {\par\noindent\hrulefill\vrule width10pt height2pt depth2pt} ``` -------------------------------- ### Build ktex.web with multiple change files and view TIE output Source: https://www.overleaf.com/learn/latex/How_Overleaf_created_the_TeX_primitive_reference_data This example demonstrates applying a series of change files to `tex.web` to generate `ktex.web`, a composite WEB file suitable for the Web2C process. It includes the TIE command and its typical output, showing the files being processed and progress indicators. ```bash tie -m ktex.web tex.web tex.ch enctex.ch synctex-def.ch0 synctex-mem.ch0 synctex-mem.ch2 synctex-rec.ch0 synctex-rec.ch1 synctex-rec.ch2 tex-binpool.ch This is TIE, CWEB Version 2.4. Copyright (c) 1989,1992 by THD/ITI. All rights reserved. (tex.web) (tex.ch) (enctex.ch) (synctex-def.ch0) (synctex-mem.ch0) (synctex-mem.ch2) (synctex-rec.ch0) (synctex-rec.ch1) (synctex-rec.ch2) (tex-binpool.ch) ....500....1000....1500....2000....2500....3000....3500....4000....4500 ....5000....5500....6000....6500....7000....7500....8000....8500....9000 ....9500....10000....10500....11000....11500....12000....12500....13000 ....13500....14000....14500....15000....15500....16000....16500....17000 ....17500....18000....18500....19000....19500....20000....20500....21000 ....21500....22000....22500....23000....23500....24000....24500.... (No errors were found.) ``` -------------------------------- ### Minimal biblatex Example Source: https://www.overleaf.com/learn/latex/Bibliography_management_with_biblatex A basic LaTeX document structure demonstrating the minimal setup for using the biblatex package to cite and print a bibliography. ```latex \documentclass{article} \usepackage[utf8]{inputenc} \usepackage[english]{babel} \usepackage{biblatex} \addbibresource{sample.bib} \begin{document} Let's cite! The Einstein's journal paper \cite{einstein} and the Dirac's book \cite{dirac} are physics related items. \printbibliography \end{document> ``` -------------------------------- ### Minimal xskak Example: Empty and Initial Chessboards Source: https://www.overleaf.com/learn/latex/Chess_notation This example demonstrates the basic usage of the `xskak` package to typeset an empty chessboard and a chessboard with pieces in their initial positions. Ensure `xskak` is loaded before using `\chessboard` and `\newchessgame` commands. ```latex \documentclass{article} \usepackage{xskak} \begin{document} \chessboard[showmover=false] \newchessgame \chessboard The small white square to the right of the second board is called the \textit{mover}. \end{document} ``` -------------------------------- ### Calling the Example TeX Macro Source: https://www.overleaf.com/learn/latex/Articles/What_is_a_TeX_token_list Demonstrates how to invoke the previously defined `\mymacro` with appropriate arguments to produce output. ```tex \mymacro abc THIS TEXT defz ``` -------------------------------- ### Example of 'blank' pages in a book class document Source: https://www.overleaf.com/learn/latex/Headers_and_footers This example demonstrates how LaTeX inserts a 'blank' page (page 2) to ensure the next chapter starts on a right-hand page when using the `book` class without `openany`. This page may still contain headers. ```latex \begin{document} \frontmatter \maketitle This is frontmatter which uses Roman numerals. \mainmatter \chapter{Where do I start} Chapter 1: A short chapter that ends on page 1. \chapter{Things I remember} Chapter 2: Starts on page 3, so \LaTeX{} inserts a ``blank'' page 2. \end{document} ``` -------------------------------- ### Example Usage of Numbered Environments Source: https://www.overleaf.com/learn/latex/Environments%23Defining_a_new_environment Demonstrates using both manually defined and \newtheorem-based numbered environments, showing how numbering resets with sections. ```latex \documentclass{article} % Define our numbered environment within the preamble \newcounter{example}[section] \newenvironment{example}[1][] {\refstepcounter{example}\par\medskip \noindent \textbf{Example~\theexample. #1} \rmfamily}{\medskip} % Another numbered environment defined with \newtheorem \usepackage{amsmath} % For the \newtheorem command \newtheorem{SampleEnv}{Sample Environment}[section] \begin{document} \section{User-defined numbered environments} \begin{example} First user-defined numbered environment (number \theexample). \end{example} \begin{example} Second user-defined numbered environment (number \theexample). \end{example} \section{More user-defined numbered environments} Note how the example numbering has restarted at 1: \begin{example} First user-defined numbered environment (number \theexample). \end{example} \begin{SampleEnv} User-defined environment created with the \verb|\newtheorem| command. \end{SampleEnv} \end{document} ``` -------------------------------- ### Enable SyncTeX with compressed output Source: https://www.overleaf.com/learn/latex/MLTeX_SyncTeX_and_EncTeX_TeX_extensions Use the -synctex=1 option to enable SyncTeX and generate a compressed .synctex.gz output file. ```bash pdftex -synctex=1 myfile.tex ``` -------------------------------- ### Incorrect Display Math Termination with Single $ Source: https://www.overleaf.com/learn/latex/Errors/Display_math_should_end_with_%24%24 This example shows how starting display math with '$$' and ending with a single '$' causes the 'Display math should end with $$' error. ```latex \documentclass{article} \usepackage[textwidth=8cm]{geometry} \begin{document} \noindent \verb|$$ E=mc^2$| generates an error because the math is started by \texttt{\$\\$} but terminated by a single \texttt{\$}: $$ E=mc^2$ \noindent\verb|$$ E=mc^2$ $| also generates an error because of the space between the terminating \texttt{\$} characters: $$ E=mc^2$ $ \end{document} ``` -------------------------------- ### Minimal Beamer Presentation Example Source: https://www.overleaf.com/learn/latex/Beamer A basic Beamer document structure to create a title page and a content frame. Use this as a starting point for simple presentations. ```latex \documentclass{beamer} %Information to be included in the title page: \title{Sample title} \author{Anonymous} \institute{Overleaf} \date{2021} \begin{document} \frame{\titlepage} \begin{frame} \frametitle{Sample frame title} This is some text in the first frame. This is some text in the first frame. This is some text in the first frame. \end{frame} \end{document} ``` -------------------------------- ### Example Usage of Boxed Environment Source: https://www.overleaf.com/learn/latex/Environments%23Defining_a_new_environment Demonstrates using the 'boxed' environment with and without providing a value for the optional first argument. ```latex \documentclass{article} % Note the default value for the first % argument is provided by [This is a box] \newenvironment{boxed}[2][This is a box]{\begin{center} Argument 1 (\#1)=#1\[1ex] \begin{tabular}{|p{0.9\textwidth}|} \hline\ Argument 2 (\#2)=#2\[2ex] } { \\\\hline \end{tabular} \end{center} } \begin{document} \textbf{Example 1}: Use the default value for the first argument: \begin{boxed}{Some preliminary text} This text is \textit{inside} the environment. \end{boxed} This text is \textit{outside} the environment. \vskip12pt \textbf{Example 2}: Provide a value for the first argument: \begin{boxed}[This is not the default value]{Some more preliminary text} This text is still \textit{inside} the environment. \end{boxed} This text is also \textit{outside} the environment. \end{document} ``` -------------------------------- ### Incorrect \verb command with mismatched delimiters Source: https://www.overleaf.com/learn/latex/Errors/LaTeX_Error%3A_%5Cverb_ended_by_end_of_line This example shows incorrect usage of the \verb command where the opening delimiter is omitted or mismatched, leading to errors. Always ensure the start and end delimiters are identical and present. ```latex \verb{\frac{1}{2}} ``` ```latex \verb \frac{1}{2} ``` ```latex {\verb \frac{1}{2}} ``` ```latex \verb!\frac{1}{2} ``` -------------------------------- ### Basic Multicolumn Layout Source: https://www.overleaf.com/learn/latex/Multiple_columns%23Inserting_vertical_rulers This example shows how to set up a basic three-column layout using the `multicols` environment. The optional header text can include sections and paragraphs. ```latex \documentclass{article} \usepackage{blindtext} \usepackage{multicol} \title{Multicols Demo} \author{Overleaf} \date{April 2021} \begin{document} \maketitle \begin{multicols}{3} [ \section{First Section} All human things are subject to decay. And when fate summons, Monarchs must obey. ] \blindtext\blindtext \end{multicols} \end{document} ``` -------------------------------- ### Correct \verb command usage with delimiters Source: https://www.overleaf.com/learn/latex/Errors/LaTeX_Error%3A_%5Cverb_ended_by_end_of_line The \verb command requires matching start and end delimiters. Any character can be used as a delimiter, provided it does not appear within the text to be typeset verbatim. This example uses '!' as the delimiter. ```latex \verb!\frac{1}{2}! ``` -------------------------------- ### Create Proof Environments with amsthm Source: https://www.overleaf.com/learn/latex/Theorems_and_proofs Utilize the 'proof' environment provided by the amsthm package to visually distinguish mathematical proofs from regular text. This example also shows defining a 'lemma' environment. ```latex \documentclass{article} \usepackage[english]{babel} \usepackage{amsthm} \newtheorem{theorem}{Theorem}[section] \newtheorem{lemma}[theorem]{Lemma} \begin{document} \section{Introduction} \begin{lemma} Given two line segments whose lengths are \(a\) and \(b\) respectively there is a real number \(r\) such that \(b=ra\). \end{lemma} \begin{proof} To prove it by contradiction try and assume that the statement is false, proceed from there and at some point you will arrive to a contradiction. \end{proof} \end{document} ``` -------------------------------- ### Infinite Glue Example Source: https://www.overleaf.com/learn/latex/Articles/How_TeX_Calculates_Glue_Settings_in_an_%5Chbox Demonstrates the use of 'infinite' stretch and shrink components using fil and fill units within \hskip. This allows glue to stretch or shrink by any desired amount. ```tex \hskip 3pt plus 2fil minus 1fill ``` -------------------------------- ### Mix Arabic (RTL) and LTR languages with LuaLaTeX Source: https://www.overleaf.com/learn/latex/Multilingual_typesetting_on_Overleaf_using_babel_and_fontspec Use babel with the bidi=basic option for LuaLaTeX, which offers comprehensive support for complex scripts and bidirectional typesetting. This example includes Arabic text and basic font setup. ```latex % Arabic text in this example is from % https://github.com/latex3/babel/blob/main/samples/lua-arabic.tex \documentclass{article} \usepackage[english,bidi=basic]{babel} \babelprovide[import,main]{arabic} \babelfont{rm}{FreeSerif} \babelfont{sf}{FreeSans} \babelfont{tt}{FreeMono} \begin{document} الكهرمان اسمه باليونانية الإيلقطرون[3] (معرب ἤλεκτρον إيلكترون أي ذو البريق، ومنه الإلكترون عند الفيزيائيين، وعليه تسمية الكهرباء في الفارسية برق)، واشتق منه اسم فاعليتيه فسمي إلكترسمس (ηλεκτρ‌ισμός) للدلالة على الكهرباء. أما باللاتينية فالكلمة للكهرباء هي إيلكترستاس (ēlectricitās)، وهي مشتقة من إيلكتركس (ēlectricus) أي شبيه الكهرمان. \end{document} ``` -------------------------------- ### Demonstrate \marginpar with different alignments Source: https://www.overleaf.com/learn/latex/Margin_notes This example showcases the \marginpar command with conditional text for left and right pages, and demonstrates \raggedright and \raggedleft for alignment. It requires the geometry and hyperref packages for page setup and URL support. ```latex \documentclass[twoside]{article} \usepackage[a4paper, marginparwidth=75pt, total={10cm, 10cm}]{geometry} \usepackage{hyperref} \usepackage{marginnote} \begin{document} \section{Lorem Ipsum} \footnote{Source text: Wikipedia (\url{https://en.wikipedia.org/wiki/Lorem_ipsum})}But I must explain to you how all this mistaken idea of reprobating pleasure and extolling pain arose. To do so, I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. \marginpar[Note 1: text for left-hand side text]{Note 1: text for right-hand side of pages, it is set justified.} No one rejects, dislikes or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but occasionally circumstances occur in which toil and pain can procure him some great pleasure. \marginpar[Note 2: text for left-hand side text]{\raggedright Note 2: text for right-hand side of pages, it is not justified, but uses \texttt{\string\raggedright}.} To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure? [33] On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammeled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. \marginpar[\raggedleft Note 3: text for left-hand side of pages, it is not justified, but uses \texttt{\string\raggedleft}]{Note 3: text for left-hand side of pages}But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains. \end{document} ``` -------------------------------- ### Basic modiagram Environment Setup Source: https://www.overleaf.com/learn/latex/Molecular_orbital_diagrams This snippet demonstrates the minimal setup for creating a molecular orbital diagram using the `modiagram` environment. It includes importing the package and defining a single atom with its basic energy sub-levels. ```latex \documentclass{article} \usepackage{modiagram} \begin{document} First example atoms: \begin{modiagram} \atom{left}{1s, 2s, 2p} \end{modiagram} \end{document} ``` -------------------------------- ### Basic Portuguese Setup with pdfLaTeX Source: https://www.overleaf.com/learn/latex/Portuguese This example demonstrates the essential packages and configurations for typesetting Portuguese using pdfLaTeX. Ensure `fontenc` and `babel` are included for correct character rendering and language features. The `hyphenat` package with custom hyphenation rules is also shown. ```latex \documentclass{article} % \usepackage[utf8]{inputenc} is no longer required (since 2018) %Set the font (output) encoding %-------------------------------------- \usepackage[T1]{fontenc} %Not needed by LuaLaTeX or XeLaTeX %-------------------------------------- %Portuguese-specific commands %-------------------------------------- \usepackage[portuguese]{babel} %-------------------------------------- %Hyphenation rules %-------------------------------------- \usepackage{hyphenat} \hyphenation{mate-mática recu-perar} %-------------------------------------- \begin{document} \tableofcontents \vspace{2cm} %Add a 2cm space \begin{abstract} Este é um breve resumo do conteúdo do documento escrito em Português. \end{abstract} \section{Seção introdutória} Esta é a primeira seção, podemos acrescentar alguns elementos adicionais e tudo será escrito corretamente. Além disso, se uma palavra é um caminho muito longo e tem de ser truncado, babel irá tentar truncar corretamente, dependendo do idioma. \section{Segunda seção} Esta seção é para ver o que acontece com comandos de texto que definem \[ \lim x = \theta + 152383.52 \] \end{document} ``` -------------------------------- ### Use a Custom LaTeX Package Source: https://www.overleaf.com/learn/latex/Writing_your_own_package This document demonstrates how to use the custom 'examplepackage' with the 'red' option. It includes the necessary \documentclass, \usepackage, and \makeindex commands, and shows how to use the custom 'example' environment and '\important' command. ```tex \documentclass{article} \usepackage[utf8]{inputenc} \usepackage[red]{examplepackage} \makeindex \title{Package Example} \author{Team Learn ShareLaTeX} \date{ } \begin{document} \maketitle \section{Introduction} In this document a new package is tested. This package allows special numbered environments \begin{example} This text is inside a special environment, some boldface text is printed at the beginning and a new indentation is set. \end{example} Also, there's a special command for \important{important!words} that will be printed in a special \important{colour} depending on the parameter used in the \important{package} importation statement. Because it's \important{important}. \printindex \end{document} ``` -------------------------------- ### Define Custom Environment with Nested Counters Source: https://www.overleaf.com/learn/latex/Counters Use \counterwithin to link a custom counter to a section counter, ensuring it resets with each new section. The starred version \counterwithin* prevents redefinition of \theexample. This setup is useful for creating numbered examples within sections. ```latex \documentclass{article} \counterwithin{equation}{section} \newcounter{example} \counterwithin*{example}{section} \newenvironment{example}[1][]{\stepcounter{example}%\par\vspace{5pt}\noindent \fbox{\textbf{Example~\thesection.\theexample}}%\hrulefill\par\vspace{10pt}\noindent\rmfamily}{\par\noindent\hrulefill\vrule width10pt height2pt depth2pt\par} \begin{document} \section{First equation} Some introductory text... \begin{example} \begin{equation} f(x)=\frac{x}{1+x^2} \end{equation} \end{example} \subsection{More detail} \begin{example} Here we discuss \begin{equation} f(x)=\frac{x+1}{x-1} \end{equation} ... but don't say anything \end{example} \subsubsection{Even more detail} \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{Third equation} \begin{example} The following function... \begin{equation} f_1(x)=\frac{x+1}{x-1} \end{equation} ..is a function \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} ``` -------------------------------- ### Complete LaTeX Document Example Source: https://www.overleaf.com/learn/latex/Integrals%2C_sums_and_limits A full LaTeX document demonstrating integrals, multiple integrals, sums, products, and limits, including necessary packages and sections. ```latex \documentclass{article} \title{Integrals, Sums and Limits} \author{Overleaf} \date{} \usepackage{amsmath} \begin{document} \maketitle \section{Integrals} Integral \(\int_{a}^{b} x^2 dx\) inside text. \medskip The same integral on display: \[ \int_{a}^{b} x^2 \,dx \] and multiple integrals: \begin{gather*} \iint_V \mu(u,v) \,du\,dv \ \iiint_V \mu(u,v,w) \,du\,dv\,dw \ \iiiint_V \mu(t,u,v,w) \,dt\,du\,dv\,dw \ \idotsint_V \mu(u_1,\dots,u_k) \,du_1 \dots du_k \ \oint_V f(s) \,ds \end{gather*} \section{Sums and products} Sum \(\sum_{n=1}^{\infty} 2^{-n} = 1\) inside text. The same sum on display: \[ \sum_{n=1}^{\infty} 2^{-n} = 1 \] Product \(\prod_{i=a}^{b} f(i)\) inside text. The same product on display: \[ \prod_{i=a}^{b} f(i) \] \section{Limits} Limit \(\lim_{x\to\infty} f(x)\) inside text. The same limit on display: \[ \lim_{x\to\infty} f(x) \] \end{document} ``` -------------------------------- ### Combining \offinterlineskip with Non-zero \lineskip Source: https://www.overleaf.com/learn/latex/Articles/How_to_change_paragraph_spacing_in_LaTeX This LaTeX example demonstrates how to use \offinterlineskip with a non-zero \lineskip value to achieve specific line spacing effects. It includes document setup, geometry package for page size, and inputting a text file with custom macros. ```latex \documentclass{article} \title{Demonstrating non-zero lineskip} % Choose a conveniently small page size \usepackage[paperheight=16cm,paperwidth=12cm,textwidth=8cm]{geometry} \begin{document} \offinterlineskip % This sets \lineskip to 0pt \setlength{\lineskip}{5pt} % We want non-zero \lineskip \input text.tex % A generated TeX file which defines the macros % \mytextA and \mytextB, each of which typesets a paragraph \mytextA % Typeset a paragraph % Now change \lineskip to a flexible glue value and typeset % another paragraph \setlength{\lineskip}{5pt plus5pt minus5pt} \mytextA \end{document} ``` -------------------------------- ### Include a LaTeX file using \include Source: https://www.overleaf.com/learn/latex/Management_in_a_large_project%23Inputting_and_including_files Use \include{filename} to insert the content of filename.tex. The file should not contain LaTeX preamble code. LaTeX will start a new page before processing the inputted material. Each \include'd file gets its own .aux file. ```latex \include{filename} ``` -------------------------------- ### Enable SyncTeX: Output .synctex Source: https://www.overleaf.com/learn/latex/MLTeX_EncTeX_and_SyncTeX_TeX_extensions Use this command-line option to enable SyncTeX and generate an uncompressed synchronization file (.synctex). ```bash pdftex -synctex=-1 myfile.tex ``` -------------------------------- ### Define Custom Example Environment Source: https://www.overleaf.com/learn/latex/Counters%23Introduction_to_LaTeX_counters Defines a custom LaTeX environment named 'example'. It increments a counter and formats the output with a box containing 'Example' followed by section and example numbers, separated by a horizontal rule. ```latex \newenvironment{example}[1][]{% \stepcounter{example}% \par\vspace{5pt}\noindent \fbox{\textbf{Example~\thesection.\theexample}}% \hrulefill\par\vspace{10pt}\noindent\rmfamily}% {\par\noindent\hrulefill\vrule width10pt height2pt depth2pt} ``` -------------------------------- ### Enable SyncTeX: Output .synctex.gz Source: https://www.overleaf.com/learn/latex/MLTeX_EncTeX_and_SyncTeX_TeX_extensions Use this command-line option to enable SyncTeX and generate a gzipped synchronization file (.synctex.gz). ```bash pdftex -synctex=1 myfile.tex ``` -------------------------------- ### Constructing a Fixed-Width Horizontal Box with Flexible Glue Source: https://www.overleaf.com/learn/latex/Articles/Pandora%E2%80%99s_%5Chbox%3A_Using_LuaTeX_to_Lift_the_Lid_of_TeX_Boxes This example demonstrates creating a 100pt wide \hbox. It uses \hskip with flexible 'plus' and 'fill' components to distribute space and ensure the box reaches the target width. ```tex \hbox to100pt{ A\hskip4pt plus3pt minus 2pt B% \hskip 0pt plus 2fil C% \hskip 0pt plus 2fill D% \hskip 0pt plus 3fill} ``` -------------------------------- ### Remove Counter Link with `\counterwithout` Source: https://www.overleaf.com/learn/latex/Counters%23Introduction_to_LaTeX_counters Demonstrates using `\counterwithout{example}{section}` to make the `example` counter independent of the `section` counter. This prevents the `example` counter from resetting at the beginning of each new section. ```latex \section{First equation} \begin{example} \begin{equation} f(x)=\frac{x}{1+x^2} \end{equation} \end{example} \subsection{Second equation} \begin{example} \begin{equation} f(x)=\frac{x+1}{x-1} \end{equation} \end{example} \vspace{6pt}\noindent Note how the \texttt{example} counter is reset at the start Section \ref{sec:n0}. \section{Third equation} \label{sec:n0} \begin{example} \begin{equation} f(x)=\frac{x+1}{x-1} \end{equation} \end{example} \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} \section{Fourth equation} \label{sec:n1} \begin{example} \begin{equation} f(x)=\frac{x^2+x^3}{1+x^3} \end{equation} \end{example} \section{Fifth equation} \label{sec:n2} \begin{example} \begin{equation} f(x,k)=\frac{x^2-x^k}{1+x^3} \end{equation} \end{example} ``` -------------------------------- ### Example \hbox with Stretchable Glue Source: https://www.overleaf.com/learn/latex/Articles/How_TeX_Calculates_Glue_Settings_in_an_%5Chbox This \hbox demonstrates the use of \hskip with varying stretch components (pt, fil, fill, filll). It serves as the basis for calculating glue settings. ```tex \hbox to100pt{ A\hskip4pt plus3pt minus 2pt% B\hskip 0pt plus 2fil% C\hskip 0pt plus 2fill% D\hskip 0pt plus 3fill% } ``` -------------------------------- ### Use Custom LaTeX Environment with Default and Provided Arguments Source: https://www.overleaf.com/learn/latex/Environments Demonstrates using the custom 'boxed' environment. The first example uses the default value for the optional argument, while the second provides a custom value. ```latex \documentclass{article} % Note the default value for the first % argument is provided by [This is a box] \newenvironment{boxed}[2][This is a box]{\begin{center} Argument 1 (\#1)=#1\[1ex] \begin{tabular}{|p{0.9\textwidth}|} \hline\ Argument 2 (\#2)=#2\[2ex] } { \\\hline \end{tabular} \end{center} } \begin{document} \textbf{Example 1}: Use the default value for the first argument: \begin{boxed}{Some preliminary text} This text is \textit{inside} the environment. \end{boxed} This text is \textit{outside} the environment. \vskip12pt \textbf{Example 2}: Provide a value for the first argument: \begin{boxed}[This is not the default value]{Some more preliminary text} This text is still \textit{inside} the environment. \end{boxed} This text is also \textit{outside} the environment. \end{document} ``` -------------------------------- ### Define Custom Environment for Examples Source: https://www.overleaf.com/learn/latex/Counters Defines a custom 'example' environment that increments a counter and formats the output with a boxed title including section and example numbers. This environment is typically used within a document that employs \counterwithin or \counterwithout. ```latex \newenvironment{example}[1][]{\stepcounter{example}%\par\vspace{5pt}\noindent \fbox{\textbf{Example~\thesection.\theexample}}%\hrulefill\par\vspace{10pt}\noindent\rmfamily}{\par\noindent\hrulefill\vrule width10pt height2pt depth2pt\par} ``` -------------------------------- ### Basic Nomenclature Example Source: https://www.overleaf.com/learn/latex/Nomenclatures This is a fundamental example demonstrating how to use the `nomencl` package to create a simple list of symbols and their descriptions. ```latex \documentclass{article} \usepackage{nomencl} \makenomenclature \begin{document} Here is an example: \nomenclature{\(c\)}{Speed of light in a vacuum} \nomenclature{\(h\)}{Planck constant} \printnomenclature \end{document} ```