Month
- Refactor AI code for a forest diagramby projetmbc on November 22, 2025 at 9:40 pm
In the code below, made using the "AI" Claude, there is too much copying and pasting of lines like the ones shown below. What is the best way to refactor the full code? archivefile/.style={ before typesetting nodes={ content/.wrap value={ \textcolor{orange!80}{\faFileArchive}\ ##1 } } } Here is the full code. \documentclass{article} \usepackage{forest} \usepackage{fontawesome5} \definecolor{foldercolor}{RGB}{124,166,198} \definecolor{filecolor}{RGB}{88,88,88} \forestset{ dir tree/.style={ for tree={ font = \sffamily, grow' = 0, child anchor = west, parent anchor= south, anchor = west, calign = first, inner ysep = 1pt, inner xsep = 1.75pt, text depth = 0pt, edge path = { \noexpand \path[draw, \forestoption{edge}] (!u.south west) +(7.5pt,0) |- (.child anchor)\forestoption{edge label}; }, before typesetting nodes={ if n=1 {insert before={[,phantom]}} {} }, fit = band, before computing xy = {l = 15pt}, } }, open/.style={ before typesetting nodes={ content/.wrap value={ \textcolor{foldercolor}{\faFolderOpen}\ ##1 } } }, closed/.style={ before typesetting nodes={ content/.wrap value={ \textcolor{foldercolor}{\faFolder}\ ##1 } } }, file/.style={ before typesetting nodes={ content/.wrap value={ \textcolor{filecolor}{\faFile}\ ##1 } } }, codefile/.style={ before typesetting nodes={ content/.wrap value={ \textcolor{filecolor}{\faFileCode}\ ##1 } } }, pdffile/.style={ before typesetting nodes={ content/.wrap value={ \textcolor{red!70}{\faFilePdf}\ ##1 } } }, textfile/.style={ before typesetting nodes={ content/.wrap value={ \textcolor{filecolor}{\faFile*}\ ##1 } } }, imagefile/.style={ before typesetting nodes={ content/.wrap value={ \textcolor{blue!70}{\faFileImage}\ ##1 } } }, archivefile/.style={ before typesetting nodes={ content/.wrap value={ \textcolor{orange!80}{\faFileArchive}\ ##1 } } }, } \begin{document} \subsection*{Exemple d'arborescence de fichiers} \begin{forest} dir tree [system, open [config, closed [settings.conf, textfile] [database.yml, codefile] ] [doc, open [manual.pdf, pdffile] [README.md, textfile] [images, closed [logo.png, imagefile] [banner.jpg, imagefile] ] ] [lib, closed [utils.py, codefile] [helpers.js, codefile] [archive.zip, archivefile] ] [test, open [test\_unit.py, codefile] [test\_integration.py, codefile] [fixtures, closed [data.json, file] ] ] ] \end{forest} \subsection*{Exemple simple} \begin{forest} dir tree [system, open [config, closed] [Dog, closed] [lib, closed] [test, closed] ] \end{forest} \end{document}
- There is a problem for triangles which are capable of partitioning eachother, which also coincide at one vertex. I am having trouble debugging itby Jasper on November 21, 2025 at 5:45 am
I am writing a software which is supposed to take a set of triangles, where some of the members of the set are capable of partitioning one another, and performing all possible partitioning. I built Lua functions which are capable of detecting and performing most intersections. Unfortunately, there appears to be a particular case which is causing me some trouble. For example, consider the following diagram where I deliberately used a complicated case to show that my algorithm works in most cases. [Unfortunately, you need to run the GitHub version of the package :-(. This is because I want to fix this bug and write new documentation before making another release.] \documentclass[tikz,border=1cm]{standalone} \usepackage{lua-tikz3dtools} % https://github.com/Pseudonym321/TikZ-Animations/tree/master1/TikZ/lua-tikz3dtools \begin{document} \pgfmathsetmacro{\i}{-pi/4} \begin{tikzpicture} \useasboundingbox[scale=2] (-1,-1) rectangle (1,1); \setobject[ name = {T} ,object = { matrix_multiply( matrix_multiply( euler(pi/2,pi/3,7*pi/6) ,translate(0,0,-5) ) ,matrix_multiply( { {1,0,0,0} ,{0,1,0,0} ,{0,0,1,0} ,{0,0,0,1} } ,matrix_multiply(xscale(1),yscale(1)) ) ) } ] \setobject[ name = {I} ,object = { matrix_inverse(T) } ] \foreach \j in {2,3,1,0}{ \appendsurface[ ustart = {-2} ,ustop = {2} ,usamples = {2} ,vstart = {-2} ,vstop = {2} ,vsamples = {2} ,transformation = {matrix_multiply(euler(\j+\i,2*\j,\j),T)} ,x = {u} ,y = {v} ,z = {\j/10} ,fill options = { preaction = { \ifnum\j=0 fill = red \fi \ifnum\j=2 fill = green \fi \ifnum\j=1 fill = yellow \fi \ifnum\j=3 fill = blue \fi ,fill opacity = 0.6 } ,postaction = { draw = black ,ultra thin ,line join = round ,line cap = round } } ,filter = { abs(matrix_multiply(A,I)[1][3])<1.01 and abs(matrix_multiply(B,I)[1][3])<1.01 and abs(matrix_multiply(C,I)[1][3])<1.01 and abs(matrix_multiply(A,I)[1][2])<1.01 and abs(matrix_multiply(B,I)[1][2])<1.01 and abs(matrix_multiply(C,I)[1][2])<1.01 and abs(matrix_multiply(A,I)[1][1])<1.01 and abs(matrix_multiply(B,I)[1][1])<1.01 and abs(matrix_multiply(C,I)[1][1])<1.01 } ] } \appendsolid[ ustart = {-1} ,ustop = {1} ,usamples = {2} ,vstart = {-1} ,vstop = {1} ,vsamples = {2} ,wstart = {-1} ,wstop = {1} ,wsamples = {2} ,transformation = {T} ,x = {u} ,y = {v} ,z = {w} ,fill options = { preaction = { fill = gray ,fill opacity = 0.5 } ,postaction = { draw = black ,ultra thin ,line join = round ,line cap = round } } ] \displaysegments \end{tikzpicture} \end{document} Gif: This is a picture of four planes intersecting, clipped by a cube. Currently, for the clipping (filtering) to work, projective transformations currently do not work, only affine ones do. This will eventually be fixed, of course. So it works, and all is fine and well - why are we here? Well, in the above diagram, each plane is offset by a small (and in each case different) translation. If this translation weren't there (and even with it there sometimes), we are faced with two triangles, which are capable of partitioning one another, which are not partitioned. I have the sense (possibly wrong) that this case wherre partitioning fails is when two triangles are non-coplanar, and meet at a vertex with the rest of their bodies visually passing through each other. It appears that my functions are not detecting and/or are not partitioning this case. For example, without the translation (it's a small difference, look at the z key), we get the following horrible graphic. \documentclass[tikz,border=1cm]{standalone} \usepackage{lua-tikz3dtools} % https://github.com/Pseudonym321/TikZ-Animations/tree/master1/TikZ/lua-tikz3dtools \begin{document} \pgfmathsetmacro{\i}{-pi/4} \begin{tikzpicture} \useasboundingbox[scale=2] (-1,-1) rectangle (1,1); \setobject[ name = {T} ,object = { matrix_multiply( matrix_multiply( euler(pi/2,pi/3,7*pi/6) ,translate(0,0,-5) ) ,matrix_multiply( { {1,0,0,0} ,{0,1,0,0} ,{0,0,1,0} ,{0,0,0,1} } ,matrix_multiply(xscale(1),yscale(1)) ) ) } ] \setobject[ name = {I} ,object = { matrix_inverse(T) } ] \foreach \j in {2,3,1,0}{ \appendsurface[ ustart = {-2} ,ustop = {2} ,usamples = {2} ,vstart = {-2} ,vstop = {2} ,vsamples = {2} ,transformation = {matrix_multiply(euler(\j+\i,2*\j,\j),T)} ,x = {u} ,y = {v} ,z = {0} ,fill options = { preaction = { \ifnum\j=0 fill = red \fi \ifnum\j=2 fill = green \fi \ifnum\j=1 fill = yellow \fi \ifnum\j=3 fill = blue \fi ,fill opacity = 0.6 } ,postaction = { draw = black ,ultra thin ,line join = round ,line cap = round } } ,filter = { abs(matrix_multiply(A,I)[1][3])<1.01 and abs(matrix_multiply(B,I)[1][3])<1.01 and abs(matrix_multiply(C,I)[1][3])<1.01 and abs(matrix_multiply(A,I)[1][2])<1.01 and abs(matrix_multiply(B,I)[1][2])<1.01 and abs(matrix_multiply(C,I)[1][2])<1.01 and abs(matrix_multiply(A,I)[1][1])<1.01 and abs(matrix_multiply(B,I)[1][1])<1.01 and abs(matrix_multiply(C,I)[1][1])<1.01 } ] } \appendsolid[ ustart = {-1} ,ustop = {1} ,usamples = {2} ,vstart = {-1} ,vstop = {1} ,vsamples = {2} ,wstart = {-1} ,wstop = {1} ,wsamples = {2} ,transformation = {T} ,x = {u} ,y = {v} ,z = {w} ,fill options = { preaction = { fill = gray ,fill opacity = 0.5 } ,postaction = { draw = black ,ultra thin ,line join = round ,line cap = round } } ] \displaysegments \end{tikzpicture} \end{document} It appears that there is a problem for triangles which are capable of partitioning one another, which also coincide at a single vertex. I am having trouble debugging it. These are the main functions of the document which I am suspect of (it's a huge pipeline of interacting functions, all from the Lua file in the package, if you want to just go there): --- returns the partition of the first triangle into three subtriangles, --- if it intersects the second, otherwise produces nil --- @param T1 table<table<number>> the first triangle --- @param T2 table<table<number>> the second triangle --- @return table<table<table<number>>,table<table<number>>,table<table<number>>> table of sub triangles local function triangle_triangle_partition(T1, T2) local I = triangle_triangle_intersections(T1, T2) if I == nil then return nil end if #I == 0 then return nil end if #I == 1 then return nil end if #I ~= 2 then assert(false, ("I is not 2, it is instead: %f"):format(#I)) end local IO = I[1] local IU = vector_subtraction(I[2], IO) local I_basis = {IO[1], IU[1]} local T1A = {T1[1], T1[2]} local T1AU = vector_subtraction({T1A[2]}, {T1A[1]}) local T1A_basis = {T1A[1], T1AU[1]} local T1B = {T1[2], T1[3]} local T1BU = vector_subtraction({T1B[2]}, {T1B[1]}) local T1B_basis = {T1B[1], T1BU[1]} local T1C = {T1[3], T1[1]} local T1CU = vector_subtraction({T1C[2]}, {T1C[1]}) local T1C_basis = {T1C[1], T1CU[1]} local T2A = {T2[1], T2[2]} local T2AU = vector_subtraction({T2A[2]}, {T2A[1]}) local T2A_basis = {T2A[1], T2AU[1]} local T2B = {T2[2], T2[3]} local T2BU = vector_subtraction({T2B[2]}, {T2B[1]}) local T2B_basis = {T2B[1], T2BU[1]} local T2C = {T2[3], T2[1]} local T2CU = vector_subtraction({T2C[2]}, {T2C[1]}) local T2C_basis = {T2C[1], T2CU[1]} local points = {} local non_intersecting = nil local int1 = line_line_intersection(I_basis, T1A_basis) if int1 == nil then int1 = {solution = {}} end if #int1.solution ~= 0 then local t = int1.solution[1] local intersect = vector_addition( IO, scalar_multiplication(t, IU) ) if point_line_segment_intersecting(intersect, T1A) then table.insert(points, intersect) else non_intersecting = "T1A" end else non_intersecting = "T1A" end local int2 = line_line_intersection(I_basis, T1B_basis) if int2 == nil then int2 = {solution = {}} end if #int2.solution ~= 0 then local t = int2.solution[1] local intersect = vector_addition( IO, scalar_multiplication(t, IU) ) if point_line_segment_intersecting(intersect, T1B) then table.insert(points, intersect) else non_intersecting = "T1B" end else non_intersecting = "T1B" end local int3 = line_line_intersection(I_basis, T1C_basis) if int3 == nil then int3 = {solution = {}} end if #int3.solution ~= 0 then local t = int3.solution[1] local intersect = vector_addition( IO, scalar_multiplication(t, IU) ) if point_line_segment_intersecting(intersect, T1C) then table.insert(points, intersect) else non_intersecting = "T1C" end else non_intersecting = "T1C" end -- if #points == 3 then return nil end -- if #points == 1 then return nil end if #points ~= 2 then -- print("Partition failure: got", #points, "points") -- print("Triangle 1:", T1) -- print("Triangle 2:", T2) -- print("Non-intersecting edge:", non_intersecting) -- for i, p in ipairs(points) do -- print("Point", i, p[1][1], p[1][2], p[1][3]) -- end return nil --assert(false, "triangle_triangle_partition doesn't have exactly two points") end local quad = {} local tri1 local A, B = points[1], points[2] table.insert(quad, A[1]) table.insert(quad, B[1]) if non_intersecting == "T1A" then table.insert(quad, T1A[1]) table.insert(quad, T1A[2]) tri1 = {A[1], B[1], T1B[2]} elseif non_intersecting == "T1B" then table.insert(quad, T1B[1]) table.insert(quad, T1B[2]) tri1 = {A[1], B[1], T1C[2]} elseif non_intersecting == "T1C" then table.insert(quad, T1C[1]) table.insert(quad, T1C[2]) tri1 = {A[1], B[1], T1A[2]} end quad = centroid_sort(quad) return { tri1 = tri1, tri2 = {quad[1], quad[2], quad[3]}, tri3 = {quad[3], quad[4], quad[1]} } end --- produces exactly zero, or exactly two intersection points between two triangles --- @param T1 table<table<number>> a triangle defined by its vertices --- @param T2 table<table<number>> another triangle defined by its vertices --- @return table<table<number>> a matrix of exactly zero or exactly two points nothing else local function triangle_triangle_intersections(T1, T2) local edges1 = { {T1[1], T1[2]}, {T1[2], T1[3]}, {T1[3], T1[1]} } local edges2 = { {T2[1], T2[2]}, {T2[2], T2[3]}, {T2[3], T2[1]} } local points = {} --- appends a point to a list if it is unique --- @param P table<table<number>> a point local function add_unique(P) -- if not P then return nil end for _, Q in ipairs(points) do if point_point_intersecting(P, Q) then return nil end end table.insert(points, P) end -- Check all edge pairs for _, E1 in ipairs(edges1) do local intersect = line_segment_triangle_intersection(E1, T2) if intersect ~= nil then add_unique(intersect.intersection) end end for _, E2 in ipairs(edges2) do local intersect = line_segment_triangle_intersection(E2, T1) if intersect ~= nil then add_unique(intersect.intersection) end end if #points ~= 2 then -- print(("two triangles intersected at %f points"):format(#points)) -- print(fmt_matrix(T1)) -- print(fmt_matrix(T2)) return nil --assert(false, ("two triangles intersected at %f points"):format(#points)) end return points end --- determines the intersection coefficients and intersection point of a line segment and triangle, if it exists, or returns nil --- @param L table<table<number>> line segment defined by endpoints --- @param T table<table<number>> triangle defined by vertices --- @return table<table<table<number>>,table<table<number>>>|nil the solution coefficients and literal R3 intersection point local function line_segment_triangle_intersection(L, T) local eps = 0.0000001 local num = 0 for _, P1 in ipairs(L) do for _, P2 in ipairs(T) do if distance({P1}, {P2}) < eps then num = num + 1 end end end if num > 1 then return nil end local LO = {L[1]} local LU = vector_subtraction({L[2]}, LO) local LA = {LO[1], LU[1]} local TO = {T[1]} local TU = vector_subtraction({T[2]}, TO) local TUA = {TO[1], TU[1]} local TV = vector_subtraction({T[3]}, TO) local TVA = {TO[1], TV[1]} local TA = {TO[1], TU[1], TV[1]} local TUVA = { vector_addition(TO, TU)[1] ,vector_subtraction(TV, TU)[1] } local coeffs = line_plane_intersection(LA, TA) if coeffs == nil then return nil end if #coeffs.freevars == 0 then local t = coeffs.solution[1] if 0-eps<=t and t<=1+eps then local I = vector_addition( LO, scalar_multiplication(t, LU) ) if point_in_triangle(I, T) then return { solution = coeffs, intersection = I } end end end return nil end --- obtains the coordinates and free variables of the intersection --- between a line and a plane, each defined by their affine bases. --- @param L table<table<number>> an affine basis of a line --- @param T table<table<number>> an affine basis of a plane --- @return table<table<number>> the solution and free variables local function line_plane_intersection(L, T) local LO = {L[1]} local LU = {L[2]} local TO = {T[1]} local TU = {T[2]} local TV = {T[3]} --- LO + (t) * LU = TO + (s) * TU + (w) * TV -- (t) * LU - (s) * TU - (w) * TV = TO - LO local rhs = vector_subtraction(TO, LO) local augmented_matrix = { {LU[1][1], LU[1][2], LU[1][3]}, {-TU[1][1], -TU[1][2], -TU[1][3]}, {-TV[1][1], -TV[1][2], -TV[1][3]}, {rhs[1][1], rhs[1][2], rhs[1][3]} } local sol = gauss_jordan(augmented_matrix) if not sol then -- print("No solution: line-plane system inconsistent") return nil end if #sol.freevars > 0 then -- print("Line lies in the plane (coplanar case). Free vars:", #sol.freevars) end return sol end --- determines the solution coefficients and solution set of two line segments, or produces nil --- @param L1 table<table<number>> the first line segment --- @param L2 table<table<number>> the second line segment --- @return table<table<table<number>>,table<table<number>>>|nil the solution coefficients and solution set local function line_segment_line_segment_intersection(L1, L2) local num = 0 for _, P1 in ipairs(L1) do for _, P2 in ipairs(L2) do if distance({P1}, {P2}) < eps then num = num + 1 end end end if num ~= 0 then return nil end local L1O = {L1[1]} local L1U = vector_subtraction({L1[2]}, L1O) local L1A = {L1O[1], L1U[1]} local L2O = {L2[1]} local L2U = vector_subtraction({L2[2]}, L2O) local L2A = {L2O[1], L2U[1]} local coeffs = line_line_intersection(L1A, L2A) if coeffs == nil then return nil end if #coeffs.solution == 0 then return nil end local t, s = coeffs.solution[1], coeffs.solution[2] if 0 < t - eps and t < 1 - eps and 0 < s - eps and s < 1 - eps then return { coefficients = coeffs, intersection = vector_addition( L1O, scalar_multiplication(t, L1U) ) } end return nil end --- return coordinates and free variables for line-line intersection --- @param L1 table<table<number>> affine basis of a line --- @param L1 table<table<number>> another 1D affine basis --- @return table<table<number>> the solution and free variables local function line_line_intersection(L1, L2) local L1O = {L1[1]} local L1U = {L1[2]} local L2O = {L2[1]} local L2U = {L2[2]} -- L1O + (t) * L1U = L2O + (s) * L2U -- (t) * L1U - (s) * L2U = L1O - L2O local rhs = vector_subtraction(L2O, L1O) local augmented_matrix = { {L1U[1][1], L1U[1][2], L1U[1][3]}, {-L2U[1][1], -L2U[1][2], -L2U[1][3]}, {rhs[1][1], rhs[1][2], rhs[1][3]} } return gauss_jordan(augmented_matrix) end --- CAUTION: CHATGPT GENERATED -- Correct column-major Gauss-Jordan solver (drop-in replacement) -- M is an array of columns; each column is an array of n rows. -- Last column is RHS. Returns: -- {solution = {..}, freevars = {..}} on success -- nil on inconsistency --- @param M table<table<number>> an augmented matrix --- @return table<table<number>> the solution set and free variables local function gauss_jordan(M) -- basic validation local m = #M -- number of columns (vars + RHS) if m == 0 then return {} end local n = #M[1] -- number of rows (equations) local vars = m - 1 if vars < 1 then return nil end for c = 1, m do if #M[c] ~= n then return nil end end -- Work on a local copy local cols = {} for c = 1, m do cols[c] = {} for r = 1, n do cols[c][r] = M[c][r] end end local rank = 0 local row = 1 local pivot_cols = {} -- track pivot columns -- Gauss–Jordan elimination for col = 1, vars do -- find pivot row in column col, rows row..n local pivot_row = nil local maxval = eps for r = row, n do local v = math.abs(cols[col][r]) if v > maxval then maxval = v pivot_row = r end end if pivot_row then -- swap pivot_row with current row if pivot_row ~= row then for c = 1, m do cols[c][row], cols[c][pivot_row] = cols[c][pivot_row], cols[c][row] end end -- normalize pivot row local pivot = cols[col][row] for c = 1, m do cols[c][row] = cols[c][row] / pivot end -- eliminate column in other rows for r = 1, n do if r ~= row then local factor = cols[col][r] if math.abs(factor) > eps then for c = 1, m do cols[c][r] = cols[c][r] - factor * cols[c][row] end cols[col][r] = 0 end end end pivot_cols[#pivot_cols+1] = col rank = rank + 1 row = row + 1 if row > n then break end end end -- check for inconsistency: [0 0 ... | b] with b≠0 for r = rank+1, n do local all_zero = true for c = 1, vars do if math.abs(cols[c][r]) > eps then all_zero = false break end end if all_zero and math.abs(cols[m][r]) > eps then return nil -- inconsistent end end -- Identify free variables local freevars = {} local pivotset = {} for _,c in ipairs(pivot_cols) do pivotset[c] = true end for c = 1, vars do if not pivotset[c] then freevars[#freevars+1] = c end end -- Extract one particular solution local sol = {} for i = 1, vars do sol[i] = 0 end for k,pcol in ipairs(pivot_cols) do sol[pcol] = cols[m][k] -- solution from reduced form end return {solution = sol, freevars = freevars} end
- Randomize an enumerate list containing lstlistingby Dimitrios ANAGNOSTOU on November 19, 2025 at 10:52 am
I would like to create a randomized enumerate list whose items may contain lstlisting environments. So far, I can successfully randomize ordinary items, but items containing a lstlisting environment break the mechanism. I have a workaround, but it forces all listings to stay in fixed positions, which defeats the purpose of randomization. I would like all items—including those containing listings—to be included in the shuffle performed by \additem. Here is an example of my 'workaround' solution. \documentclass{article} % ---------- Packages ---------- \usepackage[french]{babel} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{lmodern} \usepackage{enumitem} \usepackage{xcolor} \usepackage{listings} % ----------- Style Matlab ----------- \lstdefinestyle{stylematlab}{ language=Matlab, basicstyle=\ttfamily\small, keywordstyle=\color{blue}, commentstyle=\color{green!60!black}, numbers=left, numberstyle=\tiny, stepnumber=1, frame=single } % ----------- Randomized items ----------- \usepackage{pgffor} \usepackage{pgf} \usepackage{xparse} \ExplSyntaxOn % Sequence storing the items \seq_new:N \g_myitems_seq % Add item \NewDocumentCommand{\additem}{m}{ \seq_put_right:Nn \g_myitems_seq {#1} } % Shuffle and typeset \NewDocumentCommand{\shuffleitems}{}{ \pgfmathsetseed{\number\pdfrandomseed} \seq_shuffle:N \g_myitems_seq \begin{enumerate} \seq_map_inline:Nn \g_myitems_seq {##1} \end{enumerate} } \ExplSyntaxOff \begin{document} Indiquer si chaque affirmation est vraie (V) ou fausse (F). % ---- Ajout des items ---- \additem{ \item En programmation numérique, une complexité algorithmique en $\mathcal{O}(n^2)$ est toujours préférable à une complexité en $\mathcal{O}(n \ln n)$. } \additem{ \item Les fonctions anonymes en \textsc{Matlab} ne peuvent pas être passées comme arguments à d'autres fonctions. } \additem{ \item En général, dans un problème d’optimisation, une solution optimale locale est garantie d’être aussi une solution optimale globale. } % ---- Mélange des items ---- \shuffleitems % ---- Items supplémentaires (non randomisés) ---- \begin{enumerate}[start=4] \item Exemple avec listing Matlab : \begin{lstlisting}[style=stylematlab] f = @(x) x.^2 + 1; x = -5:0.1:5; plot(x,f(x)) \end{lstlisting} \end{enumerate} \end{document} Items containing lstlisting do not behave well inside the token storage. They seem to prevent the shuffle from working properly. My temporary workaround is to keep such items outside the randomized block, but this defeats the point. Is there a way to fully integrate items containing lstlisting into the randomization process performed by \additem, without switching to the exam class and eventually exam-randomizechoices?
- Link with many %by Sebastiano on November 18, 2025 at 5:27 pm
Generally, I don't include many links in my PDFs. Until now I’ve never had problems with \href from the hyperref package: when the URL contains % characters, I escape them using \% and everything works fine. I suppose to have a URL with many % https://www.emathhelp.net/calculators/calculus-2/series-calculator/?f=n%5E%280.9999%29*%281%2F%28n-2%29-1%2F%28n-1%29%29&var=n&a=3&b=%2Binf \documentclass[12pt]{article} \usepackage{hyperref} \begin{document} \href{https://www.emathhelp.net/calculators/calculus-2/series-calculator/?f=n\%5E\%280.9999\%29*\%281\%2F\%28n-2\%29-1\%2F\%28n-1\%29\%29&var=n&a=3&b=\%2Binf}{t} \end{document} I put for every % the symbol \ thus the \href work correctly. If I use the original link provides me with an incomplete URL because the first % acts as a comment (see the picture below). But if a URL contains, for example, twenty % characters, what is the correct way to handle them so that \href works properly without put manually twenty \?
- circuiTikZ: Transistor where the lines of the emitter and collector start at the same pointby cis on November 18, 2025 at 2:56 pm
Is there a circuitikz-package-like way, to get a transistor like this? This means where the lines of the emitter and collector start at the same point. \documentclass[margin=5mm]{standalone} \usepackage{circuitikz} \begin{document} \begin{circuitikz}[] \draw (0,0) node[npn](T){}; \draw (T.B) node[left]{B} (T.C) node[above]{C} (T.E) node[below]{E}; \end{circuitikz} \end{document}
- help with 3D Surface plot TikZby Mark Roelands on November 16, 2025 at 9:20 pm
Can someone please help with coding the surface plot for $\sqrt{(x - 1)^2 + y^2} + \sqrt{(x + 1)^2 + y^2} - 4 = -|z|$ in TikZ for my article in LateX? I have been trying, but can't seem to manage it. This is what I have so far, it only plots one half of the surface on a square but not within the disk: \begin{tikzpicture} \begin{axis}[ hide axis, colormap/cool, ] \addplot3[ mesh, samples=50, domain=-2:2, ] {deg(sqrt((x - 1)^2 + y^2) + sqrt((x + 1)^2 +y^2) - 4)}; \end{axis} \end{tikzpicture}
- fourier-otf font package: incorrect size of integral symbol in \displaystyle math modeby jowe_19 on November 15, 2025 at 2:51 pm
For the past few weeks, my integrals have not been displaying in display-style math mode. I can reproduce the issue with this small minimal example. How can I fix this? \documentclass[11pt]{report} \usepackage{mathtools} \usepackage{fourier-otf} \begin{document} Test \( \int_0^1 \). Test \( \displaystyle\int_0^1 \). \end{document}
- How to draw a rectangle in tikz at scale 0.9 without broken line joinsby msrd0 on November 15, 2025 at 10:28 am
I have a tikz picture that I apply scale=0.9 to that \draws a rectangle, like this: \documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture}[scale=0.9] \draw[draw=red, fill=red, fill opacity=0.3, thick] (0.24999999999999997, 5.8) -| (0.44999999999999996, 6.2) -| cycle; \end{tikzpicture} \end{document} This results in one corner not having the correct line join: If I would remove the scale argument, the line joint would be correct, but the whole picture no longer fits on my page. I also would like to avoid having to manually multiply all coordinates with 0.9. As a workaround, I could draw a second rectangle over it, with the "missing" corner in a different location. Is there a better solution?
- How can I draw a filled plane using tikz/closedcycleby katang on November 13, 2025 at 11:26 pm
I want to make a 3-D figure with a spatial diagram line and draw its projections onto the three axes planes. For better visibility, I want to mark the projections' positions with shaded planes. The MWE and the result are shown below. It looks like that \closedcycle wants to close anyhow in the plane containing the z-axis. Is there any option to draw a plane perpendicular to the z-axis (i.e., to the other two planes)? (I also tried \addplot3 [surf, fill] and fill between, but to no avail.) \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} \begin{axis} %XZ plane \addplot3 [fill=red!20,opacity=30,draw=none,fill opacity=0.5,] coordinates {(0,120,3900)(3,120,3900)} \closedcycle; %YZ plane \addplot3 [fill=green!20,opacity=30,draw=none,fill opacity=0.5,] coordinates {(3,-40,3900)(3,120,3900)} \closedcycle; %XY plane \addplot3 [fill=blue!20,opacity=30,draw=none,fill opacity=0.5,] coordinates {(0,-40,3900)(3,120,3900)} \closedcycle; \end{axis} \end{tikzpicture} \end{document} As a reply to @Jasper, I attach the figure here I need one more plane, for the blue diagram line. The thick spatial curve is projected to the axial planes. Thanks to all for your helpfulness and the useful hints.
- Error linked to active characters?by Bibi on November 13, 2025 at 5:46 pm
This MWE gives an error that disappears if line #3 or line #4 are commented. I would say that this has probably something to do with active characters, but I am not able to understand what goes wrong here. Any help? \documentclass[9pt, professionalfont]{beamer} \usepackage{pgfplots} \usepackage[french]{babel} % No error if this line (or the next one) is commented \usetikzlibrary{babel} \begin{document} \begin{frame} \begin{overlayarea}{\textwidth}{5cm} \only<1>{ \begin{center} \begin{tikzpicture} \begin{axis} \addplot {x^2+4}; \end{axis} \end{tikzpicture} \end{center} } \end{overlayarea} \end{frame} \end{document}
- How to avoid \big having more space than \left?by allo on November 13, 2025 at 4:03 pm
When using \big instead of \left \right I get some unwanted extra space. Example: \documentclass{article} \usepackage{amsmath} \usepackage{stix} \begin{document} \begin{align*} \big\langle \star \hat A \big\rangle \\ % Bad \left\langle \star \hat A \right\rangle % Good \end{align*} \end{document} I want to use \big, because in my more complicated equation \left \right would cause larger angles to be used that look worse than using \big for my equation.
- \tikzmath defined functions sometimes won't parse in \addplot, producing spurious errorsby Francis Cook on November 13, 2025 at 12:38 pm
This is my first post so the graph may not appear and/or the format may look weird. Apologies if that is so. The graph is produced when the line \addplot[red, thick] {myexp(x,4)}; is commented out When included, numerous errors result, seemingly spurious because it is not being parsed as expected, for example "! Illegal unit of measure (pt inserted)." Unfortunately, I cannot see my mistake. I have tried everything I can think of, including spaces before and/or after pretty much every reference and even trying to use "declare function" (but I couldn't make that work the with complex, iterative logic). I am puzzled by the fact that a simple, two argument function (myfunc) can be called successfully, one with more complex logic (expterm) can be called successfully, but a complex one, with a loop and calls (myexp) fails. Any help/suggestions gratefully received. I am hoping to fix this with \tikzmath rather than use the equivalent pgfplots function definitions etc The code is as follows \documentclass{article} \usepackage{pgfplots} \usetikzlibrary{math} \pgfplotsset{compat=newest} \begin{document} \begin{tikzpicture} % Define the function using tikzmath - scope is within the tikzpicture % note that the \tikzmath block is sensitive to blank lines % so don't leave any lines blank % inclde non math lines like drawing commands within double curly braces {{ }} \tikzmath{ function myfunc(\x,\a) { return sin(\x r) + \a*\x; }; function expterm(\x,\n) { if \n == 0 then { return 1; } else { if \n == 1 then { return \x; } else { return \x ^ \n / factorial(\n); }; }; }; function myexp(\x,\n) { \s=0; for \i in {0,1,...,\n-1}{ \s=\s+expterm(\x,\i); }; return \s; }; } \begin{axis}[ domain=-2*pi:2*pi, xmin=-2*pi, xmax=2*pi, ymin=-3, ymax=3, restrict y to domain=-3:3, samples=100, axis lines=middle, xtick={ -2*pi, -3*pi/2, -pi, -pi/2, pi/2, pi, 3*pi/2, 2*pi }, xticklabels={ $-2\pi$, $-\frac{3\pi}{2}$, $-\pi$, $-\frac{\pi}{2}$, $\frac{\pi}{2}$, $\pi$, $\frac{3\pi}{2}$, $2\pi$ }, width=14cm, height=14cm, xlabel=$x$, ylabel={$y = f(x)$}, title={Function defined in \texttt{\textbackslash tikzmath}} ] % Use the tikzmath function in an addplot \addplot[blue, thick] {myfunc(x,0.3)}; \addplot[green, thick] {expterm(x,3)}; % \addplot[red, thick] {myexp(x,4)}; \end{axis} \end{tikzpicture} \end{document}
- Strange node naming scope issues across two tikzpictures environment?by Explorer on November 13, 2025 at 1:27 am
This post raised from my previous answer, and pascal974's comment: Consider the following two codes: \documentclass[tikz,border=5pt]{standalone} \usetikzlibrary{positioning} \begin{document} \begin{tikzpicture} \foreach[remember=\n as \lastn] \n in {0,...,5}{ \node (\n) [right = of \lastn] {\n}; } \end{tikzpicture} \end{document} It would complain that as expected: ! Package pgf Error: No shape named `0' is known. See the pgf package documentation for explanation. Type H <return> for immediate help. ... l.10 } ? However, if I add \tikz \node (0) {}; in another tikzpicture, the definition of node's namespace looks like "penetrated" the tikzpicture, which affect the next node named 0 as below: \documentclass[tikz,border=5pt]{standalone} \usetikzlibrary{positioning} \begin{document} \tikz \node (0) {}; \begin{tikzpicture} \foreach[remember=\n as \lastn] \n in {0,...,5}{ \node (\n) [right = of \lastn] {\n}; } \end{tikzpicture} \end{document} My question is: Why the namespace of \node is shared across different tikzpictures? It looks like some information leak happened here? I believe that this case is different with cfr's this excellent solution.
- How come when filling in TikZ, there is a visible gap between adjacent fills?by Jasper on November 12, 2025 at 1:00 am
How come when filling in TikZ, there is a visible gap between adjacent fills? \documentclass[tikz,border=1cm]{standalone} \begin{document} \begin{tikzpicture} \fill (0,0) -- (1,1) -- (1,0) -- cycle; \fill (0,0) -- (1,1) -- (0,1) -- cycle; \end{tikzpicture} \end{document}
- How to distribute TikZ pics along entire path consisting of multiple subpaths?by dsacre on November 11, 2025 at 7:25 pm
Assume the following: One wants to distribute (ideally: equally by length) TikZ pics along a path consisting of multiple subpaths. MWE \documentclass[border=5pt]{standalone} \usepackage{tikz} % DESCRIPTION: Definition of picture for positioning along the path \tikzset{ mypic/.pic={ \path[fill=cyan](0,0)circle(5pt); } } \begin{document} \begin{tikzpicture} \path[draw=black] (0,0)--++(0,2.5) arc(0:180:5) --++(0,-2.5) arc(180:360:5) % DESCRIPTION: Distributes pictures only on last part of path foreach \t in {0, 0.125, ..., 1}{ pic[pos=\t]{mypic} } ; \end{tikzpicture} \end{document} Result Goals Distribute pics along complete path (without copy pasting the foreach construct to each subpath) Achieve equal distribution by length over the whole path Question Is there a way to achieve this with plain TikZ or a TikZ library? Ideally, the solution should be as programmatically as possible, since it is intended to be used in an animation later on.
- Why does activating tagging in a footnote-heavy document increase the PDF file size much more with lualatex than with pdflatex?by Senex on November 11, 2025 at 11:32 am
Update: following the code change in pdfmanagement (mentioned by @UlrikeFischer in the comments) to mitigate the underlying luatex bug, the test code in the question now produces a much smaller tagged PDF with lualatex — only 384kB (1.42× the untagged size), smaller than is produced with pdflatex. The code below generates a 70 page "lorem ipsum" document with ~5–10 footnotes per page. Activating tagging (just changing tagging=off to tagging=on) produces a much larger increase in PDF file size when compiling with lualatex compared with pdflatex, although the output of show-pdf-tags seems to indicate that the tagging structure is actually smaller for lualatex: pdflatex lualatex tagging=off PDF size 297kB 270kB tagging=on PDF size 529kB 870kB relative size of PDFs 1.78 3.22 show-pdf-tags output size 929kB 810kB If I remove the \footnote command, so that everything appears as body text, the difference is much smaller: pdflatex lualatex tagging=off PDF size 206kB 231kB tagging=on PDF size 326kB 397kB relative size of PDFs 1.58 1.71 show-pdf-tags output size 357kB 359kB These results are from an up-to-date TeX Live 2025. So: (1) What is going on? (2) Is it possible to reduce the file size produced by lualatex? (Is there some setting I should have applied?) (I understand that tagging is under active development and this might be a transient issue. I noticed this when converting a private book style to be tagging-compatible.) Code for the document: \DocumentMetadata{ pdfversion=2.0, pdfstandard=UA-2, lang=la, tagging=off, } \documentclass{book} \ExplSyntaxOn \cs_new:Npn\generatecomplexfile { \int_zero:N\l_tmpa_int \int_do_until:nNnn{\l_tmpa_int}>{500}{ \int_incr:N\l_tmpa_int \group_begin: \int_set:Nn\l_tmpa_int{\int_mod:nn{\l_tmpa_int}{100}+1} \int_set:Nn\l_tmpb_int{\int_mod:nn{\l_tmpa_int}{19}+1} \lipsum_aux:ee{\int_use:N\l_tmpa_int}{\int_use:N\l_tmpb_int} \footnote{\lipsum_aux:ee{\int_use:N\l_tmpa_int}{1}}~ \par \group_end: } } \cs_new:Npn\lipsum_aux:nn #1#2 { \lipsum[#1][1-#2] } \cs_generate_variant:Nn\lipsum_aux:nn{ ee } \ExplSyntaxOff \usepackage{lipsum} \begin{document} \generatecomplexfile \end{document}
- How can I use a counter with a dynamically-created name in Latex Expl3?by Jean-Louis Brabant on November 10, 2025 at 6:55 am
I am new to Expl3 and would like to be able to use a counter by retrieving its name dynamically, performing this operation within a user command for other stuff. I am unable to display the counter value. I may be making a beginner's mistake, but I don't know where it might be... Here is the minimal example I am working on : \documentclass{article} \ExplSyntaxOn % declare counter \int_new:N \g_strxdiv_leveliv_division_count_int % initialize counter \int_gset:Nn \g_strxdiv_leveliv_division_count_int { 1 } % Construct the counter name dynamically \cs_new:Npn \__strxgen_construct_counter_name:nn #1% first variable part #2% second variable part { g_strx#1_#2_count_int % used as-is, \__strxgen_construct_counter_name:nn { div } { leveliv } gives the correct name ('g_strxdiv_leveliv_count_int') } % For user purposes \NewDocumentCommand\Test { m m } { \int_use:c { \__strxgen_construct_counter_name:nn { #1 } { #2 } } % <other stuff should be placed here using the counter once "reconstructed"> } \ExplSyntaxOff \begin{document} \Test{div}{leviv} % displays the error messg 'You can't use '\relax' after the. (...)' ) % Thinking it was an expansion issue with \int_use:c, I've tried with \exp_args:... without more success. \end{document} Thank you so much for your help.
- Simplified space-separated vector macro not workingby Hugh on November 9, 2025 at 4:03 pm
I'm trying to write a macro that allows me to turn something like this: \vec{12 12 12} ...into something like this: \begin{bmatrix}12 \\ 12 \\ 12\end{bmatrix} Here is the code I wrote for it: \renewcommand{\vec}[1]{\begin{bmatrix}{\vecHelper#1}\end{bmatrix}} \newcommand{\vecHelper}[1]{#1\@ifnextchar\@sptoken{\\\vecHelper}{\@ifnextchar\egroup{}{\vecHelper}}} The idea is to keep parsing characters one at a time, adding \\ upon seeing a space and terminating the recursion upon the end of the input (in this case, seeing an \egroup). When I then try writing: $$\vec{12 12 12}$$ it actually displays correctly: However, I get the following error messages (I use Overleaf): I suspect the issue has something to do with the ending brace not being there at some point when it is supposed to, but I'm not sure when or why and I'm not sure how to fix it. In case it's of any use, I tried adding debugging characters to my macro to see if it was functioning correctly, and I didn't see any issues: \renewcommand{\vec}[1]{\begin{bmatrix}{\vecHelper#1}\end{bmatrix}} \newcommand{\vecHelper}[1]{#1\@ifnextchar\@sptoken{a\\\vecHelper}{b\@ifnextchar\egroup{c}{d\vecHelper}}} $$\vec{12 12 12}$$ This also gives the same errors as above. Thank you all for your time.
- beautification of a block matrixby RIPAN DAS on November 9, 2025 at 3:21 pm
I am looking for suggestions on how to improve the visual presentation of a block matrix I created in LaTeX. I'm hoping to "beautify" it and make it easier to read. Here is the code: \documentclass{article} \usepackage{amsmath} \newcommand{\bigzero}{\mbox{\normalfont\Large\bfseries 0}} \newcommand{\rvline}{\hspace*{-\arraycolsep}\vline\hspace*{-\arraycolsep}} \begin{document} \[ \begin{bmatrix} \begin{matrix} \dfrac{\partial \tilde{x}_1}{\partial x_1}(x) &\cdots & \dfrac{\partial \tilde{x}_1}{\partial x_n}(x)\\ \vdots &\ddots &\vdots \\ \dfrac{\partial \tilde{x}_1}{\partial x_1}(x) &\cdots & \dfrac{\partial \tilde{x}_1}{\partial x_n}(x) \end{matrix} & \rvline & \bigzero \\ \hline \bigzero & \rvline & \begin{matrix} \dfrac{\partial \tilde{x}_1}{\partial x_1}(x) &\cdots & \dfrac{\partial \tilde{x}_1}{\partial x_n}(x)\\ \vdots &\ddots &\vdots \\ \dfrac{\partial \tilde{x}_1}{\partial x_1}(x) &\cdots & \dfrac{\partial \tilde{x}_1}{\partial x_n}(x) \end{matrix} \end{bmatrix} \] \end{document} as you can see, there is no gap between the horizontal line and the rows just above and below it. i want to make it better and look beautiful and if possible some more beautification.
- TikZ: How to draw a 3D shape by defining its 2D cross-section and 3D path?by Diaa on November 8, 2025 at 12:24 pm
For the following, I would like to draw a 3D shape by sweeping the cross-section (i.e., rectangle or circle) along the 3D path from its start to end coordinates, while having, if possible, the option to draw the hidden edges as dashed lines based on the 3d view view angles control the smoothness of connectivity at vertices (getting right-angled bends or curved ones). \documentclass[tikz,border=10pt]{standalone} \usepackage{tikz} \usetikzlibrary{3d,calc,perspective} \begin{document} \begin{tikzpicture}[3d view={140}{40}] \begin{scope}[->, black, thin] \draw (0,0,0)-- (3,0,0) node[anchor=north east]{$x$}; \draw (0,0,0) -- (0,3,0) node[anchor=north west]{$y$}; \draw (0,0,0) -- (0,0,3) node[anchor=south]{$z$}; \end{scope} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \coordinate (start1) at (3,1,2); \coordinate (end1) at (3,1,-2); \draw[canvas is xy plane at z=2, fill=blue!10] ($(start1) - (0.25,0.5)$) rectangle ($(start1) + (0.25,0.5)$); \coordinate (v1) at ($(start1)+(0,0,1)$); \coordinate (v2) at ($(v1)+(-2,0,0)$); \coordinate (v3) at ($(v2)+(0,0,-6)$); \coordinate (v4) at ($(v3)+(2,0,0)$); \draw[blue] (start1) -- (v1) -- (v2) -- (v3) -- (v4) -- (end1); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \coordinate (start2) at (-3,1,2); \coordinate (end2) at (-3,1,-2); \draw[canvas is xy plane at z=2, fill=red!10] (start2) circle (0.25); \coordinate (v11) at ($(start2)+(0,0,1)$); \coordinate (v22) at ($(v11)+(2,0,0)$); \coordinate (v33) at ($(v22)+(0,0,-6)$); \coordinate (v44) at ($(v33)+(-2,0,0)$); \draw[red] (start2) -- (v11) -- (v22) -- (v33) -- (v44) -- (end2); \end{tikzpicture} \end{document}
- How can I get \enumerate to use Chinese numerals instead of Arabic ones?by neruneru on November 7, 2025 at 5:22 pm
I'm trying to set up \enumerate to use Chinese numerals (一,二,三,四……) using the zhnumber package. The effect I'm trying to achieve is this: Desired Output: The package zhnumber provides a macro to convert counters into Chinese numerals, \zhnum, and I tried using it with the enumi counter and the label option in the enumitem package. However, it looks like what happens is the label computes once when the counter is 0 instead of with every new instance of \item. This is the MWE and output: Code: \documentclass{ltjtarticle} \usepackage{zhnumber} \usepackage{enumitem} \begin{document} \begin{enumerate}[label=(\zhnum{enumi})] \item 道可道,非常道。 \item 名可名,非常名。 \item 無名天地之始。 \item 有名萬物之母。 \item 故常無欲,以觀其妙。 \item 常有欲,以觀其繳。 \end{enumerate} \end{document} Actual Output: Here, 零 is the Chinese numeral for 0. This is not the case, for instance, if you use label=\arabic{enumi}, which works as expected: I am using the ltjtarticle document class which calls the luatex-jp package (and compiles with LuaLaTeX), since I need this to typeset other things in my document. If anyone has any idea how I can fix this problem please let me know! I'm willing to use packages that aren't zhnumber but they need to be compatible with luatex-jp and ltjtarticle (ctex doesn't seem to work, for example). PS: Incidentally, is there a way to use fullwidth Arabic numerals with enumitem? In this vertical document, the fullwidth Arabic numerals would not rotate like the halfwidth ones.
- Is excludeonly still working? (TeXlive 2025)by Markus Nißl on November 7, 2025 at 8:38 am
I came across excludeonly with this question: Is there an \exclude option? Is excludeonly still working? I'm using 2003/03/14 v1.0 with TeXlive 2025. This next minimal example has file b.tex in the generated output. I only want files a.tex and c.tex in the output. \documentclass{article} \usepackage{excludeonly} \excludeonly{b} \begin{document} \include{a} \include{b} \include{c} \end{document} What am I doing wrong? Or what am I misunderstanding?
- "Hanging" corners on Tikz diagramby pwesterbaan on November 6, 2025 at 7:23 pm
I'm creating a diagram of an open box using Tikz: \documentclass[margin=5pt, convert={density=1000, size=10000}]{standalone} \usepackage{tikz} \usetikzlibrary{calc} \pagecolor[RGB]{255,255,255} \begin{document} % H-------G % /| /| % / | / | % / E----/--F % / / / / % D-------C / % | / | / % |/ |/ % A-------B \begin{tikzpicture}[ declare function={ wdth=4.35; hgt=2; x_offset=2.75; y_offset=2.75;} ] \coordinate (A) at (0,0); \coordinate (B) at (wdth,0); \coordinate (C) at (wdth,hgt); \coordinate (D) at (0,hgt); \coordinate (E) at ($(A)+(x_offset, y_offset)$); \coordinate (F) at ($(B)+(x_offset, y_offset)$); \coordinate (G) at ($(C)+(x_offset, y_offset)$); \coordinate (H) at ($(D)+(x_offset, y_offset)$); \draw[fill=black!15, line width=1pt] (A) -- (B) -- (F) -- (E) -- cycle; \draw[line width=1pt] (E) -- (F) -- (G) -- (H) -- cycle; \draw[fill=white, line width=1pt] (A) -- (E) -- (H) -- (D) -- cycle; \draw[fill=white, line width=1pt] (B) -- (F) -- (G) -- (C) -- cycle; \draw[fill=white, line width=1pt] (A) -- (B) -- (C) -- (D) -- cycle; \draw[dotted] (A) -- (E) -- (F); \end{tikzpicture} \end{document} The problem I'm having is that the lines protrude where the corners meet (likely because my line width=1pt). How do I draw this diagram without the "hanging" bits at the corners?
- Want to use LaTeX for Studentsby GowriSaro on November 6, 2025 at 6:03 am
The students don’t have knowledge of TeX but they want to use it. I heard that BakomaTeX has a facility to use LaTeX even the user doesn’t have knowledge of TeX, but I wasn’t able to use it. (The actual problem is that I’m not able to get much information regarding BakomaTeX.) Please refer me to any free LaTeX tool which is more user friendly, so that it’s more likely that the students are going to use it. I can train the students to the basic level of TeX, but what I’m looking for is something based on the WYSIWYG principle, like BakomaTeX.
- Iterated plot with TikZ, PGFPlots and foreach loopby Dominique on November 5, 2025 at 4:31 pm
I'm trying to plot an illustration of the fixed point method in which a function is evaluated repeatedly in a loop. The result should be a staircase or spiral plot on top of the plot of the function itself. I've read here about the use of \edef inside a foreach loop. The following MWE should show what I'm trying to do, but it seems to only perform a single iteration. Notes: the loop variable isn't used inside the loop. perhaps it's an illusion that only single iteration is performed and the real issue is that \xprev and \xnext aren not updated at each pass through the loop. I tried placing the updates inside the \edef, but that gives an undefined control sequence error. I also tried \pgfplotsinvokeforeach instead of \foreach, but only obtained other errors. \documentclass{standalone} \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \pgfmathdeclarefunction{g}{1}{\pgfmathparse{#1^2 - 2}} \begin{tikzpicture} \begin{axis} [ xmin = -2.5, xmax = 2.5, ymin = -3, ymax = 3, axis x line = center, axis y line = center, domain=-2.5:2.5, samples=300, ] \addplot[ultra thick] {g(x)}; % graph of g \addplot[thin] {x}; % diagonal \def\xstart{-0.75} \pgfmathsetmacro{\xprev}{\xstart}; \pgfmathsetmacro{\xnext}{g(\xprev)}; \draw[thick, blue] (\xstart, 0) -- (\xstart, \xnext) -- (\xnext, \xnext); \foreach \i in {1, 2, 3}{ \pgfmathsetmacro{\xprev}{\xnext} \pgfmathsetmacro{\xnext}{g(\xprev)} % x <- g(x) \edef\plotoneiter{% \noexpand% \draw[thick, blue] ({\xprev}, {\xprev}) -- ({\xprev}, {\xnext}) -- ({\xnext}, {\xnext}); }\plotoneiter% } \end{axis} \end{tikzpicture} \end{document} Thanks in advance for any hints! EDIT: Here is a quick sketch of what I'm trying to achieve:
- I want a command which can take two arbitrary ellipses, and shade the region between them, bounded by their mutual tangentsby Jasper on November 2, 2025 at 9:31 pm
I want a command which can take two arbitrary ellipses, and shade the region between them, bounded by their mutual tangents. \documentclass[tikz,border=1cm]{standalone} \begin{document} \begin{tikzpicture} \fill (-5,0) ellipse[x radius = 1, y radius = pi]; \fill ({sqrt(2)},e) ellipse[x radius = {sqrt(pi)}, y radius = {sqrt(e^sqrt(pi))}]; \end{tikzpicture} \end{document}
- TikZ arrow difference in different PDF-viewer(PDF-XChange-Editor v10.5.2)?by Explorer on November 1, 2025 at 6:03 pm
I have the following mwe: \documentclass[tikz,border=5pt]{standalone} \usetikzlibrary{arrows.meta} \begin{document} \begin{tikzpicture}[% foo/.tip={Latex[width=0pt 5, length=5pt]}, line cap=round,line join=round,scale=1.3 ] \begin{scope} \coordinate (A) at (-1,0); \coordinate (B) at (1,0); \coordinate (C) at (0,{sqrt(3)}); \draw[foo-foo] (A) -- (B); \draw[foo-foo] (A) -- (C); \draw[foo-foo] (B) -- (C); \end{scope} \end{tikzpicture} \end{document} Then the output's arrow differs in different PDF-viewers: case1: PDF.js in LaTeXWorkshop case2: Edge browser case3: PDF-Xchange-Editor The abnormal arrow tip only shown with PDF-Xchange-Editor. Is this the PDF-viewer to be blamed, what caused this difference? Edit to mizimizhi Z's comments(@muzimuzhiZ): The test code: \documentclass[tikz,border=5pt]{standalone} \usetikzlibrary{arrows.meta} \begin{document} \tikz \draw[line join=round, {-Latex}] (0,0) -- (1,0); \begin{tikzpicture}[ line width=5pt, line join=round ] \draw (0,0) -- (1,1) -- (1,0); \draw[line join=miter, xshift=2cm] (0,0) -- (1,1) -- (1,0); \end{tikzpicture} \end{document} While in contrast, I compared it with another PDF-viewer: foxit-PDF-editor-pro, it gives the correct result:
- With the Roboto Flex font, siunitx \micro not displayed with an upright muby Denis Bitouzé on October 31, 2025 at 11:35 am
The following MCE displays \unit{\micro\gram} as expected, that is with the (upright mu) Micro Sign character: \documentclass{article} \usepackage{fontspec} \usepackage{siunitx} \setmainfont{TeX Gyre Schola} % \setmainfont{RobotoFlex-VariableFont.ttf} \begin{document} \begin{itemize} \item Greek Small Letter Mu/Unicode char 03BC: μ/\char"03BC \item Micro Sign/Unicode char 00B5: µ/\char"00B5 \item \verb|\unit{\micro\gram}|: \unit{\micro\gram} \end{itemize} \end{document} However, if the TeX Gyre Schola font is replaced with the Roboto Flex font, \unit{\micro\gram} is displayed with a slanted mu, so not with a Micro Sign: I assume this is a bug in the Roboto Flex font, but is there anything that can be done on the (Lua)LaTeX side to resolve the issue?
- Parsing command arguments with xstring within tikzpicture blockby UnderscorePoY on October 26, 2025 at 10:26 pm
I'm trying to write a custom command to automatically adapt the shape of intervals in Tikz. I'm currently trying to pass an orientation argument to the command \intervalle to parse it via another command \intervalleParseOrientation. Here's a MWE: \documentclass[crop,tikz]{standalone} \usepackage{xstring} \newcommand{\intervalleParseOrientation}[2]{ \IfStrEqCase{#1}{ {h}{{#2}, 0} {v}{0, {#2}} }[\GenericError{}{}{}{h (horizontal) or v (vertical)}] } \newcommand{\intervalle}[1]{ \draw[|-|] (0, 0) -- (\intervalleParseOrientation{h}{1}); } \begin{document} \begin{tikzpicture} \intervalle{1}; \end{tikzpicture} \end{document} This gives the error Illegal parameter number in definition of \tikz@scan@point@coordinate., pointing at the argument within the call to \intervalle. Anyone happens to have encountered such error ? I'd really appreciate some help on that one. Thanks in advance!
- Segmented cake symbolby Sebastiano on October 26, 2025 at 9:50 pm
Let's take as an example an old request of mine, where I asked to create small symbols (eyes) to indicate the difficulty of an exercise. TikZ or symbol eyes for difficulty of examples/exercises Since I can't find a symbol, among those available in the symbol manual, that represents 1/4 of a cake to indicate time (and that can be associated with 1/2, 3/4, and 4/4), I wonder if it's possible to adapt the Marsupilam code to use a symbol that can be found in an Italian national newspaper. I think that is an image and not a symbol. \documentclass[12pt]{standalone} \usepackage{tikz} \newcommand\straightEye[1][1.2ex] {% \begin{tikzpicture}[scale=#1/1cm] \draw (0,0) circle (.5); \fill (0,0) circle (.25); \end{tikzpicture}% } \newcommand\downwardsEye[1][1.2ex] {% \begin{tikzpicture}[scale=#1/1cm] \draw (0,0) circle (.5); \fill (0,-.25) circle (.25); \end{tikzpicture}% } \newcommand\rightEye[1][1.2ex] {% \begin{tikzpicture}[scale=#1/1cm] \draw (0,0) circle (.5); \fill (.25,0) circle (.25); \end{tikzpicture}% } \begin{document} \straightEye \downwardsEye \ look at me \rightEye\rightEye \end{document}