Skip to content

feat: add width and height parameter #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ru322
Copy link

@ru322 ru322 commented Jun 12, 2025

I created a PR to add optional argument to the algo and code

Motivation

There was a need to align the height and width of algo or code when they are displayed next to each other.

This change allows for setting the width and height of these blocks, which helps in creating a more organized and visually appealing layout when aligning multiple elements.

Changes

  • add width and height argument to the algo
  • add width argument to the code
  • default width and height is auto

Usage

algo

#algo(
  title: "Floyd-Warshall",
  parameters: ("V", "E", "w"),
  width: 80%,
  height: 50%

)[
  Let $"dist"[u,v] <- infinity$ for $u,v$ in $V$\
  For $(u,v)$ in $E$:#i\
    $"dist"[u,v] <- w(u,v)$ #comment[edge weights] #d\
  For $v$ in $V$:#i\
    $"dist"[v,v] <- 0$ #comment[base case] #d\
  \
  For $k <- 1$ to $|V|$:#i\
    For $i <- 1$ to $|V|$:#i\
      For $j <- 1$ to $|V|$:#i\
        #comment(inline: true)[if new path is shorter, reduce distance]\
        If $"dist"[i,j] > "dist"[i,k] + "dist"[k,j]$:#i\
          $"dist"[i,j] <- "dist"[i,k] + "dist"[k,j]$#d#d#d#d\
  \
  Return $"dist"$
]

code

#code(
  width: 80%
)[
  ```py
  def floyd_warshall(G):
    # let G be an adjacency matrix
    dist = G
    
    for k in range(len(G)):
      for i in range(len(G)):
        for j in range(len(G)):
          if dist[i][j] > dist[i][k] + dist[k][j]:
            dist[i][j] = dist[i][k] + dist[k][j]
    
    return dist
    ```
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant