Week
- How to *locally* expose lua code in a .sty fileby Jasper on June 30, 2025 at 9:07 am
I want to make latex commands which run lua code. In particular, I want to know how to properly expose this lua code locally to a .sty file, so I don't have to require it in every newcommand. My big underlying goal here is to learn how to properly use lua and latex together. Reference: https://tex.stackexchange.com/a/742410/319072 % test.tex % arara: lualatex \documentclass[border = 1cm]{standalone} \usepackage{test} \begin{document} \begin{tikzpicture} \appendpoint{-1}{0} \appendpoint{1}{0} \appendpoint{0}{-1} \appendpoint{0}{1} \rotatepoints{math.pi/4} \renderpoints \end{tikzpicture} \end{document} % test.sty \NeedsTeXFormat{LaTeX2e}[1994/06/01] \ProvidesPackage{test} [ 2025/06/30 v0.01 LaTeX package for an inquiry on TeX.SE. ] \RequirePackage{tikz} \newcommand{\appendpoint}[2]{ \directlua{ local test = require("test") test.append_point(#1,#2) } } \newcommand{\renderpoints}{ \directlua{ local test = require("test") test.render_points() } } \newcommand{\rotatepoints}[1]{ \directlua{ local test = require("test") test.list_of_points = test.mult( test.list_of_points ,test.rotate(#1) ) } } -- test.lua local test = {} test.list_of_points = {} function test.append_point(x,y) table.insert(test.list_of_points,{x,y,1}) end function test.render_points() for i = 1, #test.list_of_points do tex.print( string.format( [[ \fill (%f,%f) circle[radius = 0.1]; ]] ,test.list_of_points[i][1] ,test.list_of_points[i][2] ) ) end end function test.mult(A,B) local rows_A = #A local columns_A = #A[1] local rows_B = #B local columns_B = #B[1] assert( columns_A == rows_B ,string.format( [[ Wrong size matrices for multiplication. Size A: %f,%f Size B: %f,%f ]] ,rows_A,columns_A ,rows_B,columns_B ) ) local product = {} for row = 1, rows_A, 1 do product[row] = {} for column = 1, columns_B, 1 do product[row][column] = 0 for dot_product_step = 1, columns_A, 1 do product[row][column] = ( product[row][column] + A[row][dot_product_step] * B[dot_product_step][column] ) end end end return product end function test.rotate(angle) return { {math.cos(angle),math.sin(angle),0} ,{math.cos(angle+math.pi/2),math.sin(angle+math.pi/2),0} ,{0,0,1} } end return test
- Combine text font from bera and math font from mathptmxby Akira on June 29, 2025 at 8:39 pm
I have a tex file: \documentclass{article} \usepackage{amssymb} \usepackage{bera} %\usepackage{mathptmx} \begin{document} Consider a measurable function $\sigma: \mathbb{R}^d \times \mathcal{P}\left(\mathbb{R}^d\right) \rightarrow \mathcal{M}_d(\mathbb{R})$ where $\mathcal{P}\left(\mathbb{R}^d\right)$ is the space of probability distributions on $\mathbb{R}^d$ equipped with the Wasserstein metric $W_2$ and $\mathcal{M}_d(\mathbb{R})$ is the space of square matrices of dimension $d$. Consider a measurable function $b: \mathbb{R}^d \times \mathcal{P}\left(\mathbb{R}^d\right) \rightarrow \mathbb{R}^d$ . Define $a(x, \mu):=\sigma(x, \mu) \sigma(x, \mu)^T$. A stochastic process $\left(X_t\right)_{t \geq 0}$ is a McKean-Vlasov process if it solves the following system: ${ }^{[3][5]}$ - $X_0$ has law $f_0$ - $d X_t=\sigma\left(X_t, \mu_t\right) d B_t+b\left(X_t, \mu_t\right) d t$ where $\mu_t=\mathcal{L}\left(X_t\right)$ describes the law of $X$ and $B_t$ denotes a $d$-dimensional Wiener process. This process is non-linear, in the sense that the associated Fokker-Planck equation for $\mu_t$ is a nonlinear partial differential equation. \end{document} When I use \usepackage{bera}, I get When \usepackage{mathptmx}, I get Is there any way to use use text font from bera and math font from mathptmx?
- Is there a TECkit equivalent in LuaTeX?by yannis on June 29, 2025 at 6:33 pm
XeTeX uses TECkit map files as a regular grammar to derive output character words from input character words. For example: U+0021 U+0060 <> U+00A1 ; produces a Spanish inverted exclamation mark from an exclamation mark followed by an ASCII grave accent. Is there, or can there be, something equivalent in LuaTeX?
- Where and why does LuaLaTeX imports the lualibs libraries?by yannisl on June 29, 2025 at 8:28 am
Consider the following MWE demonstrating that when compiling with LuaLaTeX there is no need to require("lualibs"). Where in the sources are these libraries loaded and why? \documentclass{article} \begin{document} testing \directlua{ for key,v in pairs(lualibs.module_info) do tex.print(-2,key .." = " .. v, " ") end } \end{document}
- Bidi breaks french spaces via polyglossia after numbers and periodsby Chris H on June 29, 2025 at 7:53 am
I have a document mostly in French (using polyglossia and xetex), with a phrase in Hebrew, requiring the bidi package. Merely loading bidi collapses some spaces, e.g. between a number a semi-colon or between a period and a closing quotation mark. Here's a MWE: \documentclass{book} \usepackage{titletoc} \dottedcontents{chapter}[0em]{\itshape}{2em}{1pc} \usepackage{polyglossia} \setmainlanguage[thincolonspace=true]{french} \usepackage{bidi} \begin{document} Testing: French spaces before colons, exclamation marks! question marks? around «quotation marks», and semicolons; It all works with the bidi package – unless numbers are involved, like 2025; or a period.» Commenting out bidi package re-instates the spaces. \end{document} Is there a way to patch this behaviour?
- Why don't the memoir octavo sizes match actual octavo sizes?by Conley Owens on June 28, 2025 at 11:32 pm
Why are the memoir sizes all a little smaller? For example crown octavo is 8x5.4in, but memoir has crownvopaper as 7.5x5in. Memoir Documentation: Wikipedia Book Size Page: PaperSizes.io
- QED symbol placement after TikZ-CD diagramby Peter LeFanu Lumsdaine on June 28, 2025 at 4:32 pm
I have a proof that concludes with a TikZ-CD commutative diagram. I’d like to align the QED symbol to the baseline of the text of the last row of the diagram. How can I accomplish this? (To be completely clear: by “align the QED symbol to the baseline”, I mean in the same sense that the symbol is usually vertically aligned to sit on the baseline of the last row of text of the proof.) There are many previous questions on QED symbol placement, but I can’t find one that works well in this case. The answer of End of proof symbol in tikz environment allows alignment to an arbitrary location in a TikZ picture, but works by placing a \node, so I don’t see how to adapt it to a TikZ-CD diagram. The verticalhack approach given in this answer to How align the qedsymbol after of a big formula in display mode? allows aligning the QED symbol to the lower edge of the diagram’s bounding box, which is below the text baseline of the last row — sometimes only slightly lower, but sometimes very noticeably, as in the following MWE: \documentclass[a5paper]{article} \usepackage{tikz,tikz-cd} \usepackage{amsthm,amsmath} % from https://tex.stackexchange.com/a/195443/ by egreg \newenvironment{verticalhack} {\begin{array}[b]{@{}c@{}}\displaystyle} {\\\noalign{\hrule height0pt}\end{array}} \begin{document} \begin{proof} The following diagram concludes the proof: \[ \begin{verticalhack}\begin{tikzcd} A \ar[d] \ar[r] & B & & C & D \ar[d] \\ W & X & \displaystyle \int_{x=0}^1 x^2 dx & Y \ar[r] & Z \end{tikzcd}\end{verticalhack}\qedhere \] \end{proof} \begin{proof} Standard placement for comparison: $\displaystyle \int_0^1 x^2 dx$ \end{proof} \end{document}
- Expanding macros to stringby LemeRus on June 28, 2025 at 1:37 pm
I have macros for output first char of string. \makeatletter \def\firstchar#1{\expandafter\checkfirst#1\@nil} \def\checkfirst#1{% \ifx\UTFviii@two@octets#1% \expandafter\gettwooctets \else \expandafter\@car\expandafter#1% \fi } \def\gettwooctets#1#2#3\@nil{\UTFviii@two@octets#1#2} \makeatother It works if I pass a string directly like \firstchar{Иванович} If I pass macros with english string it also works correctly. But if I try \firstchar{\developerPatron} where \newcommand{\developerPatron}{Иванович} I see error ! LaTeX Error: Invalid UTF-8 byte sequence (�\nexttoken). \nexttoken is any token following \firstchar{…} call. I tried some variants with \expandafter. Below are variants of code and mathing errors. C: \expandafter\firstchar{\developerPatron} E: ! Missing \endcsname inserted. <to be read again> \protect E: ! LaTeX Error: Invalid UTF-8 byte sequence (�\endcsname\nexttoken). C: \expandafter\firstchar{\expandafter\developerPatron} E: ! Undefined control sequence. \firstchar #1->\expandafter \checkfirst #1\@nil E:! Argument of \@car has an extra }. <inserted text> \par E: Runaway argument? {}.\,\fi \developerSurName \color@endgroup ! Paragraph ended before \@car was complete. <to be read again> \par E: ! Extra }, or forgotten \endgroup. <recently read> } C: \expandafter\firstchar\expandafter\developerPatron E: ! Missing \endcsname inserted. <to be read again> \protect E: ! LaTeX Error: Invalid UTF-8 byte sequence (�\endcsname\nexttoken). How can I expand \developerPatron to \firstchar work correctly with cyrillic strings?
- How to change `minimize` to British English Spelling in optidef packageby CroCo on June 27, 2025 at 6:16 pm
Using optidef package, one can write \documentclass{article} \usepackage{optidef} \begin{document} \begin{mini} {w}{f(w)+ R(w+6x)} {}{} \addConstraint{g(w)}{=0} \addConstraint{n(w)}{= 6} \addConstraint{L(w)+r(x)}{=Kw+p} \addConstraint{h(x)}{=0.} \end{mini} \end{document} which renders this Is it possible to modify the American spelling minimize to align with British English (i.e., minimise)?
- How to centre the parent and the child level, but not anything below?by mikebuba on June 27, 2025 at 3:14 pm
I am using the forest package and trying to adjust the picture as per my liking. So far I have managed to do most of it, but this is giving me a bit of a challenge: centre the parent text bubble in the middle of the graph reduce the distance between parent and the first child, and centre the first child text The code is here. \documentclass[border=10pt]{standalone} \usepackage[edges]{forest} \usepackage[T1]{fontenc} \tikzset{% parent/.style={align=center,text width=3cm,rounded corners=3pt, draw}, % Added draw for consistency child/.style={align=left,rounded corners=3pt, draw} % Removed text width, set align to left } \begin{document} \begin{forest} for tree={ % forked edges, draw, % Ensure all nodes are drawn rounded corners, % node options={align=center,}, % This was redundant if defined in child/parent styles % text width=2.7cm, % Removed this global text width inner sep=3pt, % Adjusted inner padding }, where level=0{% parent anchor=center, text width=3cm, % Keep text width for the root node to maintain its size s sep=1cm % Increased sibling separation for root's children }{% folder, grow'=0, if level=1{% before typesetting nodes={child anchor=north}, edge path'={(!u.parent anchor) -| (.child anchor)}, edge+={blend mode=lighten}, }{}, } [T-Type Inverter, fill=white, parent [Advantages over 2-level \& other 3-level topologies, for tree={fill=white, child}, text width=4.5cm % Keep text width for these category nodes [Lower switching losses] [Lower device stress \& lower dv/dt] [Better voltage quality \& efficiency] [Simpler \& cost-effective in 4–30 kHz range] ] [Challenges, for tree={fill=white,child}, calign with current edge, text width=2cm % Keep text width for these category nodes [Common-mode (CM) voltage] [DC link voltage oscillations \& neutral-point unbalance] ] ] \end{forest} \end{document} If I put [Challenges, for tree={fill=white,parent} It takes all the parent properties, i.e., align=centre but also text width=3cm, but I want two different text widths for left and right children. Any help would be much appreciated. Update After applying the solution below, the children and parent are not the same height:
- Use foreach loop variable in path coordinatesby Franz on June 27, 2025 at 12:36 pm
I have the following code: \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepgfplotslibrary{fillbetween} \begin{document} \begin{tikzpicture} \begin{axis}[% axis x line=center, axis y line=center, xmax=2., xmin=-1., ymax=2., ymin=-1., ] \foreach \eps in { 1.0, 0.39810717, 0.15848932, 0.06309573, 0.01 }{ \addplot[ domain=\eps/\pgfkeysvalueof{/pgfplots/xmax}:\pgfkeysvalueof{/pgfplots/xmax}, samples=100, mark=none, name path=reg, ] {\eps/x}; % \path [name path=xaxis] % (\eps/\pgfkeysvalueof{/pgfplots/xmax}, 0.0) -- % (\pgfkeysvalueof{/pgfplots/xmax}, 0.0); % \addplot[ % gray, % opacity=0.5 % ] fill between [of=reg and xaxis]; } \end{axis} \end{tikzpicture} \end{document} Adding the commented lines I get an Undefined control sequence \eps error. Using \eps in the definition of the function and domain works. But apparently I cannot use it in the coordinates of a node. Could someone give me a brief explanation why this is the case? How can I make use of the value of \eps? EDIT: Using \closedcycle as suggested by samcarter_is_at_topanswers.xyz does not work for me as I need to use \eps also in other places. This is what I want the plot to look like (loop unrolled for two cases): \path [name path=yaxis] (0.0, 0.0) -- (0.0, \pgfkeysvalueof{/pgfplots/ymax}); \addplot[ domain=1/\pgfkeysvalueof{/pgfplots/xmax}:\pgfkeysvalueof{/pgfplots/xmax}, samples=100, mark=none, name path=reg, ] {1/x}; \path [name path=xaxis] (1/\pgfkeysvalueof{/pgfplots/xmax}, 0.0) -- (\pgfkeysvalueof{/pgfplots/xmax}, 0.0); \addplot[ gray, opacity=0.5 ] fill between [of=reg and xaxis]; \path [name path=toinf] (1/\pgfkeysvalueof{/pgfplots/xmax}, 0.0) -- (1/\pgfkeysvalueof{/pgfplots/xmax}, \pgfkeysvalueof{/pgfplots/ymax}); \addplot[ gray, opacity=0.5 ] fill between [of=yaxis and toinf]; \addplot[ domain=0.1/\pgfkeysvalueof{/pgfplots/xmax}:\pgfkeysvalueof{/pgfplots/xmax}, samples=100, mark=none, name path=reg, ] {0.1/x}; \path [name path=xaxis] (0.1/\pgfkeysvalueof{/pgfplots/xmax}, 0.0) -- (\pgfkeysvalueof{/pgfplots/xmax}, 0.0); \addplot[ gray, opacity=0.5 ] fill between [of=reg and xaxis]; \path [name path=toinf] (0.1/\pgfkeysvalueof{/pgfplots/xmax}, 0.0) -- (0.1/\pgfkeysvalueof{/pgfplots/xmax}, \pgfkeysvalueof{/pgfplots/ymax}); \addplot[ gray, opacity=0.5 ] fill between [of=yaxis and toinf]; Also using \closedcycle results in the axis lines been drawn multiple times as seen here:
- Subequations side by sideby Bastian on June 27, 2025 at 8:25 am
I remember seeing papers where short (sub)equations are placed side by side, while still being identifiable with separate numbers, as they would be in an ordinary subequations environment. There should be a single tag for the line reading something like (1a,b) or (1a, 1b) or (1,2). Is there an elegant way of doing this? \documentclass[varwidth=100mm]{standalone} \usepackage{amsmath} \begin{document} \begin{minipage}{\linewidth} I would like to type something along the lines of: \begin{subequations} \begin{gather} a = 1\\ b = 2 \end{gather} \end{subequations} but get the subequations displayed side by side, like this: \begin{equation} a = 1 \qquad b = 2 \tag{1a,b} \end{equation} \end{minipage} \end{document} Addendum Here are three implementations based on the solution given by @zarko: \documentclass{article} \usepackage{amsmath} \begin{document} \begin{description} \item[Variant 1 with subequations] \begin{subequations} \begin{equation} a^2 + b^2 = c^2 \end{equation} \begin{align} \refstepcounter{equation} a & = 1 & b & = 2 \tag{\theequation, c} \end{align} \refstepcounter{equation} \begin{equation} a^2 + b^2 = c^2 \end{equation} \end{subequations} \item[Variant 2] \begin{equation} a^2 + b^2 = c^2 \end{equation} \begin{align} a & = 1 & b & = 2 \tag{\refstepcounter{equation}\theequation, \refstepcounter{equation}\theequation} \end{align} \begin{equation} a^2 + b^2 = c^2 \end{equation} \item[Variant 2 with subequations] \begin{subequations} \begin{equation} a^2 + b^2 = c^2 \end{equation} \begin{align} a & = 1 & b & = 2 \tag{\refstepcounter{equation}\theequation, \refstepcounter{equation}\theequation} \end{align} \begin{equation} a^2 + b^2 = c^2 \end{equation} \end{subequations} \end{description} \end{document}
- Aligning minipage (with figures) with the label inside custom enumerate environmentby math_inquiry on June 27, 2025 at 7:26 am
There might be an obvious solution that I have overlooked, but I need the help. I have a custom enumeration environment. Some items only include a table or a figure, or a table/figure with text. If this is the case then I need to align the table and the figure so te top of it is at the same level as the label of the item (so basically the same as normal text would appear in the list). Using both [t] or [b] with the minipage makes it so the bottom of the figure is the same height as the label. How to solve this? \documentclass[12pt, a4paper]{report} \usepackage[top=24mm, bottom=24mm, left=24mm, right=24mm]{geometry} \usepackage{blindtext} \usepackage{graphicx} \usepackage{float} \usepackage{tabularx} \usepackage{enumitem} \newlist{mylist}{enumerate}{1} \setlist[mylist]{midpenalty = -9999, label=\bfseries{\thechapter.\arabic*.}, labelsep = 2 em, labelwidth = 2 em, leftmargin =!} \begin{document} \begin{mylist} \item This looks just fine. Text starts at the same height as the label. \item \begin{minipage}{0.4\linewidth} This is text with either a figure or a table next to it. The top of the figure / table should be at level with tha table but neither [b] nor [t] does the trick (they do the same). \end{minipage} \begin{minipage}{0.3\linewidth} \centering \includegraphics[height = 3.5 cm]{example-image} \end{minipage} \end{mylist} \end{document}
- Resize \upharpoonright to denote restriction - case of LuaLaTeXby murray on June 26, 2025 at 4:46 pm
As in How resize \upharpoonright to denote math function restriction, I'm trying to use \upharpoonright to denote mathematical restriction of a function. The following source uses either the newtx fonts with pdfLateX or else the TeXGyre fonts with LuaLaTeX. The output, shown immediately below, is satisfactory with newtx and pdfLaTeX. However, with TeXGyre and LuaLaTeX, the function name to the left of the \upharpoonright is too close to the latter symbol, and the overprinting to form the restriction symbol is off: How can this be fixed for TeXGyre and LuaLaTeX? (I'm perfectly happy, if need be, to have, within a \ifTUTeX conditional, two different definitions of \restrict, one for pdfLaTeX and ther other for LuaLaTeX.) \documentclass{memoir} \usepackage{suffix} \usepackage{mathtools} % FONTS \ifTUTeX \usepackage[math-style=ISO]{unicode-math} \defaultfontfeatures{Scale=MatchLowercase, Ligatures=TeX} \defaultfontfeatures[TeXGyreTermesX]{% Does not come with a .fontspec file. UprightFont=*-Regular, BoldFont=*-Bold, ItalicFont=*-Italic, Ligatures={Common,TeX}, Extension=.otf } \setmainfont[Scale=1.0]{TeXGyreTermesX} \setmathfont{TeX Gyre Termes Math} \else % use pdflatex ... \usepackage[T2A,T1]{fontenc} \usepackage[subscriptcorrection]{newtx} \fi % def by Willie Wong https://tex.stackexchange.com/a/692146/13492: \makeatletter \newcommand\@rest[3]{% % #1 : function % #2 : \displaystyle etc % #3 : subscript / domain \begingroup #2 % \sbox0{$\m@th#2\left.\kern-\nulldelimiterspace\vphantom{#1}\littletaller\right|$}% \sbox2{$\m@th#2\upharpoonright$}% \dimen0=\ht0 % \advance\dimen0 by -\ht2 % \begingroup #2#1% \endgroup \mathclose{% \kern\nulldelimiterspace\mathclap{\usebox0}\mathclap{\raisebox{\dimen0}{\usebox2}}\kern\nulldelimiterspace}_{#3} \endgroup } \newcommand\restrict[2]{% \mathpalette{\@rest{#1}}{#2}% } \makeatother % my alternative for f | E notation \WithSuffix\newcommand\restrict*[2]{% make the whole thing an ordinary symbol \left.\kern-\nulldelimiterspace % automatically resize the bar with \right #1% the function \littletaller % pretend it's a little taller at normal size \right|_{#2}% } \newcommand{\littletaller}{\mathchoice{\vphantom{\big|}}{}{}{}} \newcommand{\from}{\protect\colon\!} \begin{document} \mainmatter \noindent $\restrict*{f}{E} \from E \to Y$, \quad $\restrict{g}{E} \from E \to Y$, \quad $\restrict{\Phi}{E} \from E \to Y$, \quad $\restrict{f}{A,B} \from X \to Y$, \quad $\restrict{f}{(A,B)} \from X \to Y$ \[ \restrict*{f}{E} \from E \to Y, \quad \restrict{g}{E} \from E \to Y, \quad \restrict{\Phi}{E} \from E \to Y, \quad \restrict{f}{A,B} \from X \to Y, \quad \restrict{f}{(A,B)} \from X \to Y \] \end{document}
- Vertically center align texts in tableby raf on June 26, 2025 at 4:03 pm
I have tried to center-align (vertically) the texts in the following way: \documentclass[a4paper,12pt]{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{geometry} \geometry{margin=0.8in} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{booktabs} \usepackage{colortbl} \usepackage{xcolor} \usepackage{enumitem} \usepackage{setspace} \usepackage{array} \usepackage{tabularx} \usepackage{multirow} \usepackage{etoolbox} \usepackage{xspace} \usepackage{mathptmx} \onehalfspacing \begin{document} \begin{table}[ht] \footnotesize \centering \begin{tabularx}{\textwidth}{|>{\raggedright\arraybackslash}m{1.8cm}|>{\raggedright\arraybackslash}X|>{\centering\arraybackslash}m{1.5cm}|>{\centering\arraybackslash}m{1.8cm}|>{\centering\arraybackslash}m{1.5cm}|>{\centering\arraybackslash}m{1.5cm}|>{\centering\arraybackslash}m{1.5cm}|} \hline \textbf{Objectives} & \textbf{Major Activities} & \textbf{Jul--Oct 2025} & \textbf{Nov 2025 --Feb 2026} & \textbf{Mar--Jun 2026} & \textbf{Jul--Oct 2026} & \textbf{Nov--Dec 2026} \\ \hline Literature review & A Brief overview of the relevant tasks. & \cellcolor{red!30} & & & & \\ \hline Theoretical and computational modeling & A Brief overview of the relevant tasks. & \cellcolor{blue!30} & \cellcolor{blue!30} & & & \\ \hline Numerical analyses & A Brief overview of the relevant tasks. & & & \cellcolor{yellow!30} & & \\ \hline Interpreting results & A Brief overview of the relevant tasks. & & & & \cellcolor{cyan!30} & \\ \hline Writing and Submission & A Brief overview of the relevant tasks. & & & & \cellcolor{magenta!30} & \cellcolor{magenta!30} \\ \hline \end{tabularx} \end{table} \end{document} But it is not giving my desired output. For the 1st two columns, the texts should be horizontally left-aligned and vertically centered. Would it be possible to auto-adjust the column width while using center alignment? Also, the header rows should be centered-aligned in both the vertical and horizontal directions.
- How to eliminate horizontal space between minipagesby steven_nevets on June 26, 2025 at 3:55 pm
The following MWO defines two commands \pageleft and \pageright that set two minipages left and right. How can I modify the code IN THE PREAMBLE so that I may put a space between the commands in the body of the document without breaking the horizontal alignment of the pages. I've tried % and \ignorespaces in various places in the preamble with no success. \documentclass{article} \newcommand{\pageleft}{% \begin{minipage}[t]{.5\textwidth} Text left \end{minipage} } \newcommand{\pageright}{% \begin{minipage}[t]{.5\textwidth} Text right \end{minipage} } \begin{document} %produces desired effect \pageleft \pageright %breaks the horizontal alignment \pageleft \pageright \end{document}
- Tikz perspective library - Draw 2D shape in perspective?by Atiroocky on June 26, 2025 at 3:12 pm
My goal is to draw some shapes on top of image (from camera) that respect the vanishing points of the image. After defining my two vanishing points coordinates, I managed to draw some basic shapes, but only from lines. (\draw[](tpp cs: x=0,y=0,z=0)--(tpp cs: x=1,y=1,z=0) My question : how can I render shapes in perspective like circle, rectangle, etc., that I usually define with \draw[](0,0)rectangle(1,2); ? In this MWE, how can I draw a "perspective" circle on the yz plane ? \documentclass{standalone} \usepackage{graphicx} \usepackage{tikz} \usetikzlibrary {% perspective, } \begin{document} \newcommand\simplecuboid[3]{% \draw[red!50,] (tpp cs:x=0,y=0,z=#3) -- (tpp cs:x=0,y=#2,z=#3) -- (tpp cs:x=#1,y=#2,z=#3) -- (tpp cs:x=#1,y=0,z=#3) -- cycle; \draw[red,] (tpp cs:x=0,y=0,z=0) -- (tpp cs:x=0,y=0,z=#3) -- (tpp cs:x=0,y=#2,z=#3) -- (tpp cs:x=0,y=#2,z=0) -- cycle; \draw[red!80,] (tpp cs:x=0,y=0,z=0) -- (tpp cs:x=0,y=0,z=#3) -- (tpp cs:x=#1,y=0,z=#3) -- (tpp cs:x=#1,y=0,z=0) -- cycle; \draw[red!50,] (tpp cs:x=0,y=#2,z=0) -- (tpp cs:x=#1,y=#2,z=0) -- (tpp cs:x=#1,y=#2,z=#3) -- (tpp cs:x=0,y=#2,z=#3) -- cycle; \draw[red!50,] (tpp cs:x=#1,y=0,z=0) -- (tpp cs:x=#1,y=#2,z=0); } \newcommand\xx{8.5} \newcommand\yy{16} \newcommand\zz{0} \begin{tikzpicture}[% 3d view={-25}{11}, perspective={ p = {(\xx,13,0)}, q = {(2.85,\yy,0)}, % r = {(0,0,\zz)} }, scale=1, vanishing point/.style={fill,circle,inner sep=2pt}] \begin{scope}[shift={(-6.5,-15,0)}] \simplecuboid{8}{15}{3} \filldraw[red, fill=red!30, fill opacity=0.2] (tpp cs: x=0,y=0,z=0)-- (tpp cs: x=0,y=15,z=0)-- (tpp cs: x=8,y=15,z=0)-- (tpp cs: x=8,y=0,z=0); \node[vanishing point,label = right:p] (p) at (\xx,13,0){}; \node[vanishing point,label = left:q] (q) at (2.85,\yy,0){}; \foreach \x in {-2,...,15}{ \draw[green!30] (tpp cs:x=\x,y=-5,z=0) -- (tpp cs:x=\x,y=20,z=0);} \foreach \y in {-5,...,20}{ \draw[green!30] (tpp cs:x=-2,y=\y,z=0) -- (tpp cs:x=15,y=\y,z=0);} \begin{scope}[dotted] \foreach \y in {0,15}{ \foreach \z in {0,3}{ \draw (tpp cs:x=0,y=\y,z=\z) -- (p.center);}} \foreach \x in {0,8}{ \foreach \z in {0,3}{ \draw (tpp cs:x=\x,y=0,z=\z) -- (q.center);}} \end{scope} \filldraw[blue, fill=green, fill opacity=0.1] (tpp cs: x=0,y=0,z=0)-- (tpp cs: x=0, y=0,z=1.5)-- (tpp cs: x=0, y=1,z=1.5)-- (tpp cs: x=0, y=1,z=0)-- cycle; \filldraw[red, fill=green, fill opacity=0.1] (tpp cs: x=0,y=3,z=1)-- (tpp cs: x=0, y=3,z=2)-- (tpp cs: x=0, y=4,z=2)-- (tpp cs: x=0, y=4,z=1)-- cycle; \end{scope} \end{tikzpicture} \end{document} Output : Thank for your help.
- How can I generate a "List of Links" like \listoffiguresby BJFE on June 26, 2025 at 10:30 am
https://www.overleaf.com/learn/latex/Lists_of_tables_and_figures It appears to be straightforward to add a list of tables or figures. Can I do the same thing to list all the urls hidden by \href{url}{label} for printing? %\documentclass[twocolumn,apl,nobalancelastpage,10pt,citeautoscript,longbibliography,floatfix]{article} \documentclass[a4paper,10pt]{report} \usepackage[hyphens]{xurl} \usepackage[dvipsnames]{xcolor} \usepackage{hyperref} \hypersetup{ colorlinks=true, linkcolor=BlueViolet, filecolor=BlueViolet, urlcolor=BlueViolet, citecolor=BlueViolet, pdftitle={Overleaf Example}, pdfpagemode=FullScreen, } \renewcommand\labelitemi{--} \begin{document} \href{https://www.youtube.com/}{YouTube} \href{https://www.wikipedia.org/}{Wikipedia} \href{https://www.feynmanlectures.caltech.edu/index.html}{Feynman Lectures} %\listofurls % - YoTube: https://www.youtube.com/ % - Wikipedia: https://www.wikipedia.org/ % - Feynman Lectures: https://www.feynmanlectures.caltech.edu/index.html \end{document} Best solution result:
- Reference a TikZ coordinate from later in the pictureby schtandard on June 26, 2025 at 8:19 am
I want to clip a tikzpicture to a shape that is derived from a node in the tikzpicture (which should also be clipped). In order to do this, I need to know the node coordinates (for clipping) before the node is defined. How can I do this? Here's an MWE. The red box marks the desired clipping path. If I uncomment the \clip path at the start of the picture, I get the error No shape `testnode' is known., of course. \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} % \clip % (testnode.north west) % -- (testnode.south west) % -- (testnode.east) % -- (testnode.north east) % -- cycle; \draw [blue, very thick] (-1,0) sin (-.5,.5) cos (0,0) sin (.5,-.5) cos (1,0); \node (testnode) {This is a test}; \draw [red] (testnode.north west) -- (testnode.south west) -- (testnode.east) -- (testnode.north east) -- cycle; \end{tikzpicture} \end{document}
- Add months or years to datesby stackoverflow21 on June 26, 2025 at 5:55 am
I'd like to add i.e. 18 month to dates in my latex documents. For example: By adding 18 months, 26/06/2025 should become 26/12/2026. However, I only managed to add days using the datetime2 package: \documentclass[a4paper]{article} \usepackage{datetime2} \usepackage{datetime2-calc} \begin{document} % format date \DTMsetdatestyle{ddmmyyyy} % present date \DTMsavedate{mydate}{2025-01-01} present date: \DTMusedate{mydate} %future date \newcount\myct % count register to store result \DTMsaveddatetojulianday{mydate}{\myct} \DTMsaveddateoffsettojulianday{mydate}{540}{\myct} % add 540 days \DTMsavejulianday{mydate}{\myct} future date: \DTMusedate{mydate} \end{document} Since the number of days to add depends on the months that lie between the dates (or a leap year, in the case of adding years), adding days is not helping me.
- Error in Springer citation templateby AXL on June 26, 2025 at 1:20 am
I am trying to run an article using the following references: @Article{Han_et_al2021a, title = {Controlling the maximum stress in structural stiffness topology optimization of geometrical and material nonlinear structures}, author = {Han, Yongsheng and Xu, Bin and Duan, Zunyi and Huang, Xiaodong}, journal = {Structural and Multidisciplinary Optimization}, volume = {64}, number = {6}, pages = {3971--3998}, year = {2021}, publisher = {Springer}, doi = {10.1007/s00158-021-03072-1} } @Article{Han_et_al2021b, title = {Topology optimization of material nonlinear continuum structures under stress constraints}, author = {Han, Yongsheng and Xu, Bin and Wang, Qian and Liu, Yuanhao and Duan, Zunyi}, journal = {Computer Methods in Applied Mechanics and Engineering}, volume = {378}, pages = {113731}, year = {2021}, publisher = {Elsevier}, doi = {10.1016/j.cma.2021.113731} } using the Springer template with the following options \documentclass[lineno,pdflatex,sn-mathphys-ay]{sn-jnl} However, I am achieving the following output: \citet{Han_et_al2021a, Han_et_al2021b}. instead of Han et al. (2021a); Han et al. (2021b) I had solved this issue by changing the bibliography style (from sn-mathphys-ay to sn-vancouver). Thanks in advance!
- Save old command with \let which was redefined in an environmentby one too many on June 25, 2025 at 5:50 pm
I am writing some notes, where for brevity, I want to have a shorthand for arrows: \def\->{\ensuremath{\rightarrow}} \def\=>{\ensuremath{\Rightarrow}} which also improves the readability of code. Due to how (la)tex handles commands (no idea), \=> also overrides \= (similar for \-> and \-) The tabbing environment redefines the command \= as a tab placing marker. Thus \begin{tabbing} Some text \= with \tabs \\ in a \> new \> line \end{tabbing} is not working anymore. I can save the old command with \let\macron\=. However, this only saves the \= (macron) outside the tabbing environment. Question: How to use \let for a command redefined inside an environment? BTW: I solved the problem by using the tabular environment, which I actually prefer. I am asking out of curiosity.
- Section and subsection numbers overlaping in the ToCby Cham on June 25, 2025 at 5:25 pm
My documents have about 20 chapters, lots of sections and subsections. The ToC is then producing some overlaps, as shown with this MWE code: \documentclass[11pt,twoside]{book} \usepackage[T1]{fontenc} \usepackage{microtype} \usepackage[letterpaper,left=1.25in,right=1in,top=0.5in,bottom=0.5in,includeheadfoot,headheight=14pt]{geometry} \usepackage[nottoc]{tocbibind} \usepackage[titles]{tocloft} \begin{document} % THE TOC: \setcounter{tocdepth}{2} \microtypesetup{protrusion=false} % To fix extra dots in ToC \tableofcontents \microtypesetup{protrusion=true} \setcounter{chapter}{15} % THE CHAPTERS: \chapter{Chapter title} \setcounter{section}{11} \section{Section title} \subsection{Subsection title} \subsection{Subsection title} \setcounter{subsection}{11} \subsection{Subsection title} \subsection{Subsection title} \end{document} Here's a preview of the spacing issue: I use the following fix, but I think it's ugly because the subsection numbers aren't aligned with their section title. There's surely a better way in fixing the spacing issue: % spacing and style of chapters: \renewcommand{\cftchappresnum}{\chaptername\ }% \renewcommand{\cftchapaftersnumb}{\newline}% \setlength{\cftchapindent}{0em} % \setlength{\cftchapnumwidth}{0em}% % spacing of sections: \renewcommand{\cftsecpresnum}{\hfill} % \renewcommand{\cftsecaftersnum}{\hspace{0.75em}} \setlength{\cftsecindent}{0em} % \setlength{\cftsecnumwidth}{4em} % %\addtolength{\cftsecnumwidth}{0em} % % spacing of subsections: %\renewcommand{\cftsubsecpresnum}{\hfill} % ?? \renewcommand{\cftsubsecaftersnum}{\hspace{0.75em}} \setlength{\cftsubsecindent}{5em} % \setlength{\cftsubsecnumwidth}{4em} % 4em %\addtolength{\cftsubsecnumwidth}{0.5ex} % ?? Adding this "fix" give the following ugliness (subsection numbers not properly aligned with the section title): Is there a way to left-align all the subsection numbers to their section title, while having a constant space between the subsection titles and their number ? More specifically: I would like to get all section numbers right-aligned, and all subsection numbers left-aligned. The space between a section title and its number should be a small constant value, and the same constant space for the subsections title and their number. Is that possible?
- Differences between \int_compare:nNnTF and \int_compare:nTFby chrispi_cookie on June 25, 2025 at 3:43 pm
I'm writing a personal package where I compare some integer variables. Because \int_compare:nNnTF is around 5 times faster than \int_compare:nTF according to expl3 interfaces I tried the comparisons with the first one and noticed some differences in the evaluation of the integer expressions between both functions. What I've done: \documentclass{article} \begin{document} \ExplSyntaxOn \int_compare:nNnTF { 0 } = { 0test } { TRUE } { FALSE } % prints: testTURE \int_compare:nNnTF { 1 } = { 0test } { TRUE } { FALSE } % prints: testFALSE \int_compare:nTF { 0 = 0test } { TRUE } { FALSE } % error (LaTeX Error: Relation 't' not among =,<,>,==,!=,<=,>=) \int_compare:nTF { 1 = 0test } { TRUE } { FALSE } % error (LaTeX Error: Relation 't' not among =,<,>,==,!=,<=,>=) \ExplSyntaxOff \end{document} I expected the errors in the last two cases, but I thought all cases should result in errors. After some research the integer expressions in \int_compare:nNnTF are evaluated basically as \the\numexpr<integer-expression>\relax and \the\numexpr0test\relax gives indeed 0test. In contrast the definition for \int_compare:nTF is more complicated to support more relational symbols. According to the documentation, the integer expressions are evaluated in the same way for both functions (quotes from the documentation): \int_compare:nNnTF: "This function first evaluates each of the ⟨int expr⟩s as described for \int_eval:n". \int_compare:nTF: "This function evaluates the ⟨int expr⟩s as described for \int_eval:n". In fact, \int_eval:n { 0test } doesn't lead to an error either and prints 0test. Of course the t from test is interpreted as a relational operator because it is not an integer expression. But is it intended that \int_compare:nTF leads to errors while \int_compare:nNnTF evaluates something that is obviously not an integer expression, even though the evaluation should work identically?
- regex search with repetition (back reference)by Vollbracht on June 25, 2025 at 10:45 am
I have a task easily to be solved with regex in general. I search for an item surrounded by matching tags. In general regex allows usage of back references (like \1) for that purpose. Unfurtunately "\1" does not seem to work in LaTeX. See this example: \documentclass{article} \ExplSyntaxOn \NewDocumentCommand{\RegExTester}{m} { \ret_tester:n { #1 } } \seq_new:N \l__ret_result_seq \cs_new_protected:Nn \ret_tester:n { \tl_set:Nn \l_my_tl { Some irrelevant content \begin {Gnotes}\item {\label {S}Salami}\item {\label {C}Gouda}\end {Gnotes}\begin {Vnotes}\item {\label {B}Chiabata}\item {\label {K}Apfelboden}\end {Vnotes} More irrelevant content } \str_set:Nn \l__regex_str { \c{begin} \s* (\{([a-zA-Z]*)notes\})% portion for back reference .*? \c{label}\s*\{\s*#1\s*\}\s*(.*?)\s*\} .* \c{end} \s* \{[a-zA-Z]*notes\}% to be replaced by back reference } \exp_args:Noo \regex_extract_once:nnNTF {\l__regex_str} {\l_my_tl} \l__ret_result_seq { \use:e { TRUE & \seq_item:Nn \l__ret_result_seq {-3} & \seq_item:Nn \l__ret_result_seq {-2} & \seq_item:Nn \l__ret_result_seq {-1} & \seq_count:N \l__ret_result_seq } } {FALSE} \\ } \ExplSyntaxOff \begin{document} \begin{tabular}{lllllll} Found & ((Key)notes) & (Key) & Item & Size\\ \RegExTester{ S }% correct: G Salami \RegExTester{ B }% should be: V Chiabata \end{tabular} \end{document} Its erroneous result is Found ((Key)notes) (Key) Item Size TRUE Gnotes G Salami 4 TRUE Gnotes G Chiabata 4 The demanded result would have second line be Vnotes V Chiabata. However replacing \{[a-zA-Z]*notes\} by \1 results in Found ((Key)notes) (Key) Item Size FALSE FALSE So how can I code a back reference in LaTeX?
- How to define a macro which ends \par\noindent and eats any following space?by cfr on June 25, 2025 at 12:25 am
I want a macro to be followed by a paragraph without indentation, even if the source includes a space before the next non-space character. This is fine if the macro takes no argument, but I do not understand how it should be done if it does take an argument. In the example below, \isbool is just a control. \istable{} and \istab{} both produce the correct output, but I do not think either does so in a reasonable way. \documentclass{article} \makeatletter \def\NoIndent#1{\noindent#1} \def\istable#1{#1\par\NoIndent} \def\isbool{b\par\noindent} % sylwad david carlisle: https://tex.stackexchange.com/questions/329949/ignore-par-after-the-end-of-a-macro-then-insert-noindent#comment808392_329949 \def\istab#1{#1\@afterindentfalse\@afterheading\par} \makeatother \begin{document} \istable{g} S \hrule \isbool S \hrule \istab{t} S \hrule \end{document} I'm pretty sure I shouldn't be using \noindent. I'm also fairly sure I shouldn't be using \@afterheading for a non-heading. I know something like this can probably be done with \futurelet or expl3 peeking, but I'm not confident that is the right way to do this in LaTeX. Ref.: Ignore \par after the end of a macro; THEN insert \noindent is the source of David's comment, but seems specific to headings. The linked code by egreg seems focused on ignoring paragraphs. However, most of the posts I found are either about retaining or adding spaces following macros, or else about getting rid of them following environments. Nonetheless, I imagine this is a duplicate of something I've just failed to find.
- \pgfplotsinvokeforeach with \pgfmathsetmacro doesn't workby Stanislas Remy on June 24, 2025 at 4:20 pm
I would like to draw straight line segments in order to highlight the abscissa and ordinate for some points on the curve of 2^x, and for that I would like to make a loop with \pgfplotsinvokeforeach and \pgfmathsetmacro but it does not work. I have those segments only for the first loop, and I do not understand why. Thanks in advance. % !TeX program = lualatex \documentclass[a4paper,10pt,twoside]{scrbook} \usepackage{tikz} \usetikzlibrary{arrows.meta} \usepackage{pgfplots} \pgfplotsset{compat=newest} \begin{document} \def\xm{0} \def\XM{3} \def\ym{0} \def\YM{8} \begin{tikzpicture}[x=1.0cm, y=1.0cm, scale=1, every node/.style={scale=1}] \begin{axis} %~~~~~~~~~~~ [ /pgf/number format/.cd , use comma,1000 sep={~} , anchor = origin, %,at={(0pt,0pt)}%, disabledatascaling, clip = false, scale only axis = true, x = 4cm, y = 1cm, %width = longueurcm, %height = hauteurcm, xmin = \xm, xmax = \XM, ymin = \ym, ymax = \YM, xlabel = $x$, ylabel = $y$, axis x line = middle, % left,% right,% none,% axis y line = middle, %left,% right,% none,% x axis line style = {arrows={-Stealth[inset=2pt, angle=30:7pt]},shorten >=-10pt, shorten <=-10pt}, y axis line style = {arrows={-Stealth[inset=2pt, angle=30:7pt]},shorten >=-10pt, shorten <=-10pt}, xtick = {\xm,...,\XM}, % \empty, % minor x tick num = 5, %xticklabels = {label pos 1,label pos 2,...,label pos n}, ytick = {\ym,...,\YM}, % \empty, % minor y tick num = 1, %yticklabels = {label pos 1,label pos 2,...,label pos n}, x tick label style = {anchor=north,yshift=-1ex,font=\normalsize,fill=white,inner sep=1pt}, y tick label style = {anchor=east,xshift=-1ex,font=\normalsize,fill=white,inner sep=1pt}, xlabel style = {anchor=west,at={(ticklabel* cs:1.0)},xshift=2ex}, ylabel style = {anchor=south,at={(ticklabel* cs:1.0)},yshift=2ex}, grid = major,% both, % minor, % %grid style = {line width=.1pt,couleur}, %major grid style = {line width=.2pt,couleur}, %minor grid style = {line width=.2pt,couleur}, ] %~~~~~~~ \addplot [id={id}, domain=\xm:\XM, samples=19, smooth, mark=*, ultra thick, color=red] gnuplot {2**x} node [right=10pt, pos=0.1, color=red, fill=white, inner sep=1pt] {}; \pgfplotsinvokeforeach{1,2,3}{ \pgfmathsetmacro{\abscisse}{1/#1}; \pgfmathsetmacro{\ordonnee}{pow(2,1/#1)}; \draw [densely dashed,color = red,thick] (\abscisse,0) -- (\abscisse,\ordonnee)-- (0,\ordonnee) ; } %~~~~~~~~~ \end{axis} \end{tikzpicture} \end{document}
- Passing arguments to style macros for 'execute at end picture' in tikz-cdby so primitive on June 24, 2025 at 10:44 am
I get some weird errors when I try to define a style macro (e.g. mystyle/.style={fill=#1}) and then use that same style macro in the execute at end picture at the end of the same tikzcd diagram's parameter list? \documentclass{article} \usepackage{tikz-cd} \usetikzlibrary{fit,backgrounds} \begin{document} \begin{tikzcd}[ mystyle/.style 2 args={fill=#1,fit={#2}}, execute at end picture={ \begin{scope}[on background layer] \node[mystyle={blue!50}{(A)(B)}] {}; \end{scope} }] |[alias=A]|A \arrow[r] & |[alias=B]|B \\ \end{tikzcd} \end{document} The compiler usually doesn't recognise the macro name (mystyle above) in the scope of the execute at end picture, and sometimes I also get "You can't use `macro parameter character #' in horizontal mode"... I have several different tikzcd diagrams, so I'd like to modify the style macro associated with each separate diagram easily, without creating lots of new style commands?
- How to align arrow directions in tikz-cd?by so primitive on June 24, 2025 at 9:35 am
In the tikzcd diagram below, the arrows aren't aligned at exactly the same angle, between rows. I also have to adjust the rotate fit angle manually, to align the fitted rectangle with the arrows. How to fix this fancy-ish diagram? \documentclass{article} \usepackage{tikz-cd} \usetikzlibrary{fit,backgrounds} \begin{document} \begin{tikzcd}[column sep={5em,between origins}, row sep=large, execute at end picture={ \begin{scope}[on background layer] \node[rectangle,fill=blue!25,inner sep=5pt,rounded corners=12pt,rotate fit=42,fit={(s1)(S1)}] {}; \node[rectangle,fill=red!25,inner sep=5pt,rounded corners=12pt,rotate fit=42,fit={(s2)(S2)}] {}; \node[rectangle,fill=red!25!yellow!40,inner sep=5pt,rounded corners=12pt,rotate fit=42,fit={(s3)(S3)}] {}; \end{scope} }] & & & & & & |[alias=S3]|C \arrow[r] & \cdots \\ & & & & |[alias=S2]|B \arrow[r] & |[alias=s3]|c \arrow[ur] \\ & & |[alias=S1]|A \arrow[r] & |[alias=s2]|b \arrow[ur] \\ \cdots \arrow[r] & |[alias=s1]|a \arrow[ur] \\ \end{tikzcd} \end{document}
- Partition matrix using bmatrixby Naraghazi on June 24, 2025 at 3:29 am
Consider this example \documentclass{article} \usepackage{amsmath} \begin{document} \begin{equation*} \left[ \begin{array}{ccc|ccc} a & 0 & 0 & & & \\ 0 & b & 0 & & \mathbf{0} & \\ 0 & 0 & c & & & \\ \hline & & & a & 0 & 0 \\ & \mathbf{0} & & 0 & b & 0 \\ & & & 0 & 0 & c \end{array} \right] \end{equation*} \end{document} which gives Can this be done using bmatrix? I am trying to avoid \left[\right] because it takes too much space, like this (upper matrices using \left[\right], lower ones using bmatrix)